iOS8中CGAffineTransform的animation看起来与iOS7中的不同

我试图find为什么animation的UIView变换属性看起来不同在iOS 8比iOS 6/7。

举个简单的例子,在iOS 8之前:

 myView.transform = CGAffineTransformRotate(CGAffineTransformIdentity, 1.57); [UIView animateWithDuration:5 animations:^{ myView.transform = CGAffineTransformTranslate(plane.transform, 100, 0); }]; 

给出预期的结果,“myView”旋转了90度并向下移动,但是在iOS8中,当翻译animation时,它开始于我无法find解释的位置(这打断了animation)。

有谁知道它的解释? 提前致谢!

CGAffineTransformIdentity在ios​​7和ios8上performance不同。 这与自动布局和大小类有关。 解决scheme是删除与ios7上的animation冲突的约束。

 // solve the constraint-animation problem if(NSFoundationVersionNumber <= NSFoundationVersionNumber_iOS_7_1) { // iOS7 remove constraints that conflict with animation if (self.centerYAlignment != nil) { self.view.removeConstraint(self.centerYAlignment) //is an IBOutlet } } else { // iOS8 constraint animations are fine } 

我认为原因只是iOS8的错误,但我使用CAAnimation,而且它在iOS8上按预期工作。

我在iOS7中也出现了生涩的旋转变换问题。 通过在容器中嵌套旋转的视图并将旋转的视图对中,解决了这个问题。

我也遇到了与缩放相同的问题。 我想这可能与旋转一样。 你可以试试吗?

 myView.transform = CGAffineTransformConcat(myView.transform , CGAffineTransformMakeRotate(1.57)); [UIView animateWithDuration:5 animations:^{ myView.transform = CGAffineTransformTranslate(plane.transform, 100, 0); }]; 

也许还有必要使用CGAffineTransformMakeTranslate和CGAffineTransformConcat,我也不确定。

最糟糕的部分是:你将不得不在iOS版本上执行if / else,因为这在iOS 7中看起来很奇怪。我希望在iOS 8发布之前,这个问题已经被Apple修复了。

我同意Pbk,它与io8中的大小类有关。 uiview控制器需要根据设备的方向使用uitraitcollectionresize。 否则,当您尝试旋转它时,您将获得纵向模式下的uiviewcontroller,而手机处于横向模式。 所以正确的步骤是旋转和覆盖uitraitcollections

这并不是完全相关的,但是我在CGAffineTransformScale挣扎着,在一个相当复杂的animation中,iOS7根本不能工作。 原来我的问题是iOS7无法同时计算与CGAffineTransformRotate 。 在iOS7中,最后一个animation调用是唯一获得animation的animation,所以只有旋转发生。 这个bug在iOS8中修复。

我的解决scheme是简化我的iOS7的animation,只是在iOS8中打开一些奇特的东西:

 //Pre-animation setup: CGFloat radians = (M_PI/180) * (-15); //Get a human-readable number in degrees self.badgeImage.alpha = 0; //Start the image as invisible self.badgeImage.transform = CGAffineTransformScale(self.badgeImage.transform, 1.5, 1.5); //Start the image as scaled bigger than normal if(NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1) { //See below. We will not be rotating the image in iOS7 self.badgeImage.transform = CGAffineTransformRotate(self.badgeImage.transform, radians); //Rotate the image if iOS8 } //Animation Pieces: //Fade in [UIView animateWithDuration: 0.5 delay:0 options:0 animations:^{ self.badgeImage.alpha = 1.0f; //Return image to opaque } completion:NULL]; //Scale with bounce [UIView animateWithDuration: 1.1 delay:0 usingSpringWithDamping:0.3 //Not as good as Android's bounce interpolator, but I'll take it initialSpringVelocity:-1.0f //A negative velocity here makes the animation appear more like gravity than spring options:0 animations:^{ self.badgeImage.transform = CGAffineTransformScale(self.badgeImage.transform, 0.67, 0.67); //Return image to its original size. These arguments are relative to its current scale. } completion:NULL]; //Rotation if(NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1) { //This second animation call negates the first one on iOS7, so remove it. [UIView animateWithDuration: 0.9 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ self.badgeImage.transform = CGAffineTransformRotate(self.badgeImage.transform, (radians * -1)); //Rotate the image back to its original orientation if iOS8 } completion:NULL]; } 

当然,如果使用混淆命名的CGAffineTransformMakeScale()函数,仍然可以在iOS7中组合多个效果。 例如,在预animation设置中,可以设置旋转和缩放,然后设置调用CGAffineTransformMakeScale(1,1)将图像重置为其原始度量( MakeScale的参数是特定的,而不是相对的 – 甚至更多混乱!)。 这并不总是可取的,比如上面的例子,“弹跳”animation也会反弹。