4

I have an app for the iPhone developed on XCode 4. It works correctly in the following environments:

  1. iPhone Simulator (iOS version 5)
  2. iOS 5 device (executed from Archive)
  3. iOS 5 device (executed from XCode build)
  4. iOS 4 device (execute from XCode build)
  5. iOS 3 device (executed from XCode build)

However, when I put the archive that works in iOS 5 on a iOS 3 or 4 device it acts funny. The exact same code works fine when run from XCode on the same device though.

When I say it acts funny, it is animating a sliding UIView in the wrong axis. I do perform a rotation transformation on the UIView before I animate it though. But again, it works fine when run directly from XCode, even on iOS 3 and 4 devices. It is only acting up in the archive and only for iOS 3 and 4. The archive works fine in iOS 5.

The rotation is done by a static call in a helper class:

+ (UIImage*)rotateImage:(UIImage *)image {
CGRect             bnds = CGRectZero;
UIImage*           copy = nil;
CGContextRef       ctxt = nil;
CGImageRef         imag = image.CGImage;
CGRect             rect = CGRectZero;
CGAffineTransform  tran = CGAffineTransformIdentity;

rect.size.width  = CGImageGetWidth(imag);
rect.size.height = CGImageGetHeight(imag);

bnds = rect;

bnds = swapWidthAndHeight(bnds);
tran = CGAffineTransformMakeTranslation(rect.size.height, 0.0);
tran = CGAffineTransformRotate(tran, M_PI / 2.0);

UIGraphicsBeginImageContext(bnds.size);
ctxt = UIGraphicsGetCurrentContext();

CGContextScaleCTM(ctxt, -1.0, 1.0);
CGContextTranslateCTM(ctxt, -rect.size.height, 0.0);

CGContextConcatCTM(ctxt, tran);
CGContextDrawImage(UIGraphicsGetCurrentContext(), rect, imag);

copy = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return copy;
}

The animation is done by:

// The first image should fall from top.
CGRect rect = boardView.frame;
rect.origin = CGPointMake(VIEW_IMAGE_X_POS, 0);
boardView.frame = rect;
[myView addSubview:boardView];

// The starting image comes down.  Then passes control to the next animation routine for the clones.
[UIView beginAnimations:@"addStartingImage" context:boardView];
[UIView setAnimationDuration:1.2];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(startingImageDidStop:finished:context:)];

// Add the new image
rect = boardView.frame;
rect.origin = CGPointMake(VIEW_IMAGE_X_POS, myView.contentSize.height - 108);
boardView.frame = rect;

// End the animation
[UIView commitAnimations];

Everything else runs fine. Any thoughts?

Andrey Zverev
  • 4,409
  • 1
  • 28
  • 34
smmelzer
  • 230
  • 2
  • 10

2 Answers2

3

Try to turn off compiler optimizations.

Something is going wrong with UI on old iOS 3.x and 4.x ARMv6 devices when compiling a release build. I have no idea why, but turning off compiler optimizations will help.

Turning off Thumb may also help you with this issue, you can go to your build settings and mouse over the "Other C Flags" option. Click on the little plus button that appears to the right of this option and add a condition for the ARMv6 architecture. Do this again to create one for the ARMv7 architecture. Under the ARMv6 architecture, add the extra compiler flag of -mno-thumb.

Thumb turned off for ARMv6

Andrey Zverev
  • 4,409
  • 1
  • 28
  • 34
  • 2
    As to why: there is supposedly a known problem with the LLVM 3.0 in Xcode 4.2 and CGPoint/CGSize, see here: http://stackoverflow.com/questions/8390606/is-there-a-way-to-compile-for-arm-rather-than-thumb-in-xcode-4. Turning off compiling for Thumb should be enough to solve the problem. – Tomasz Stanczak Jan 18 '12 at 12:37
0

Code looks fine. The only problem I'm seeing here is at: rect.origin = CGPointMake(VIEW_IMAGE_X_POS, myView.contentSize.height - 108);

Try to hard-code the myView.contentSize.height value. It is possible that the view/window might not be returning the contentSize according to the updated current device orientation.

nomann
  • 2,257
  • 2
  • 21
  • 24
  • Thanks and I can try this but if the value of contentSize was wrong, I would think that would just lengthen or shorten the slide on the correct axis, not slide on the wrong axis when archived on iOS 3 or iOS 4. It is like the whole screen orientation shifts in just this one case because the screen draws fine otherwise. – smmelzer Jan 12 '12 at 00:45