我试图找出为什么{8}转换属性的动画在iOS 8中看起来与iOS 6/7不同的原因。
举一个简单的例子,在iOS 8之前:
UIView
给出预期的结果," myView"旋转90度并向下移动,但在iOS8中,当翻译动画时,它开始于我无法找到解释的点(打破动画)。
有谁知道它的解释?提前谢谢!
答案 0 :(得分:5)
CGAffineTransformIdentity在ios7和ios8上的表现不同。这与自动布局和大小类有关。解决方案是删除与ios7上的动画冲突的约束。
// 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
}
答案 1 :(得分:2)
我认为原因只是iOS8错误,但我使用的是CAAnimation,它在iOS8上按预期工作。
答案 2 :(得分:2)
我在iOS7中也遇到了生涩旋转变换的问题。解决了这个问题,方法是将旋转的视图嵌套在容器中,并将旋转的视图居中。
答案 3 :(得分:1)
我也遇到了与缩放相同的问题。我想它可能与旋转相同。你能试试吗?
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上看起来很奇怪。我希望Apple在iOS 8发布之前或iOS 8版本都能解决这个问题。
答案 4 :(得分:0)
我同意Pbk的观点,它与io8中的大小类有关。 uiviewcontrollers需要根据设备方向使用uitraitcollections进行调整大小。否则,当您尝试旋转时,您将以纵向模式获得uiviewcontroller,而手机处于横向模式。因此,正确的步骤是旋转和覆盖uitraitcollections
答案 5 :(得分:0)
这并不是完全相关的,但我正在努力与CGAffineTransformScale
在iOS7上完全无法在相当复杂的动画中工作。事实证明我的问题是iOS7无法同时使用CGAffineTransformScale
计算CGAffineTransformRotate
。在iOS7中,您进行的最后一次动画调用是唯一获得动画的动画,因此只进行了旋转。此错误已在iOS8中修复。
我的解决方案是简化我的iOS7动画,只打开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中组合多个效果。例如,在动画前设置中,您可以设置旋转和缩放,然后设置调用CGAffineTransformMakeScale(1,1)
以将图像重置为其原始指标(MakeScale
的参数是特定的,而不是相对 - 更令人困惑!)。这并不总是可取的,例如我上面的例子&#34; bouncing&#34;动画也会反弹旋转。