简体   繁体   中英

Why is XCode archive acting different than XCode build/run on iPhone

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?

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已关闭ARMv6

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM