iOS上的仿射变换旋转的奇怪行为

我想做一个相当简单的UIImageView旋转。 基本上,我有一个完美的方形图像轮的形象,我想旋转animation下。

所以我试过这个:

- (void)testButtonPressed:(id)sender { NSLog(@"Test button pressed"); CGAffineTransform transform = CGAffineTransformMakeRotation(1.0); [UIView animateWithDuration:10.0 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{ dial.transform = transform; // "dial" is a UIImageView } completion: ^(BOOL finished){ }]; } 

会发生的是,当animation开始时,图像(大约300平方米)立即跳起了50-100像素,被“挤压”成一个狭窄的椭圆形。 之后,animation进行得很好。

我尝试使用beginAnimation而得到相同的行为。

我明白,我不了解旋转起源的东西(文中的圈子),但挤压看起来很奇怪,事实上这一切都是立即发生的(对于animation)是奇怪的。

有任何想法吗?

(这是在Xcode 4.5.1的iPhone 6.0模拟器上运行,可能只是一个模拟器的东西?)

更新:我有一个机会多一点工作(我做它之间的“真正的”工作)。 我创build了一个新的XIB,从来没有自动布局和轮是“正常的”,但背景是垂直压缩。

然后有点灵感。 我注意到图像视图在NLog转储中被标记为“autoresize”。 没有看到一种方法来从IBclosures,但确实看到你可以closures主视图上的“Autoresize Subviews”。 这是否和performance完美!

我在想,为自动布局引入的一些新function是这里的罪魁祸首。 不过不知道,如果我已经find了所有的魔法设置。

但是…仍然存在这样的问题:即使在closures任何东西的“不透明”之后,我的图像的“透明”部分在iPad上仍然是黑色的。

更新:我终于明白,我的图像是在JPG 24位模式,而不是32位模式。 这在模拟器上工作 – 纯黑色被解释为透明。 但是它在iPad上不起作用。 使用32位图像修复和(与“autoresize子视图closures,以消除奇怪的扭曲/翻译)一切都很好, 除了 …旋转> 180度animation倒退animation是”聪明“,并采取”最短path“ 。

我想我只需要将animation分成两步即可。

你为什么不用CABasicAnimation呢?

 CABasicAnimation* rotationAnimation; rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; rotationAnimation.toValue = [NSNumber numberWithFloat: -M_PI_2 ]; rotationAnimation.duration = 2.0; rotationAnimation.cumulative = YES; rotationAnimation.repeatCount = 1.0; rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; [imageView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];