I have an app for the iPhone developed on XCode 4. It works correctly in the following environments:
- iPhone Simulator (iOS version 5)
- iOS 5 device (executed from Archive)
- iOS 5 device (executed from XCode build)
- iOS 4 device (execute from XCode build)
- 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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…