ios – Autolayout违反了翻译轮换动画

ios – Autolayout违反了翻译轮换动画,第1张

概述我有UIView,我想用旋转动画它.我也想使用autolayout.我已经看到了很多stackoverflow常见问题,但我没有找到任何适用的解决方案. 那么,让我们从我的界面和动画代码开始吧;我有一个UIView图像,必须旋转.现在我有按钮,激活旋转.在屏幕截图中你可以看到红十字,这必须是旋转的中心(现在它在图像上,但我想在旋转的UIView之外设置旋转中心,我知道这可以用AnchorPoint 我有UIVIEw,我想用旋转动画它.我也想使用autolayout.我已经看到了很多stackoverflow常见问题,但我没有找到任何适用的解决方案.
那么,让我们从我的界面和动画代码开始吧;我有一个UIVIEw图像,必须旋转.现在我有按钮,激活旋转.在屏幕截图中你可以看到红十字,这必须是旋转的中心(现在它在图像上,但我想在旋转的UIVIEw之外设置旋转中心,我知道这可以用AnchorPoint存档).

这是我的旋转动画代码:

#define ROTATE_DURATION 3.0- (IBAction)rotateArrow {CGAffinetransform transform = self.hand.transform;NSLog(@"layer possition before animation x: %f; y: %f",self.hand.layer.position.x,self.hand.layer.position.y);[UIVIEw animateWithDuration:ROTATE_DURATION/3 delay:0.0 options:UIVIEwAnimationoptionCurvelinear animations:^{        self.hand.transform = CGAffinetransformRotate(transform,2*M_PI/3) ;        [self.hand layoutIfNeeded];        NSLog(@"layer possition after animation 1 x: %f; y: %f",self.hand.layer.position.y);     }    completion:^(BOol finished) {        [UIVIEw animateWithDuration:ROTATE_DURATION/3 delay:0.0 options:UIVIEwAnimationoptionCurvelinear animations:^{            self.hand.transform = CGAffinetransformRotate(transform,-2*M_PI/3) ;            [self.hand layoutIfNeeded];            NSLog(@"layer possition after animation 2 x: %f; y: %f",self.hand.layer.position.y);        }    completion:^(BOol finished) {        [UIVIEw animateWithDuration:ROTATE_DURATION/3 delay:0.0 options:UIVIEwAnimationoptionCurvelinear animations:^{            self.hand.transform = CGAffinetransformRotate(transform,0) ;            [self.hand layoutIfNeeded];            NSLog(@"layer possition after animation 3 x: %f; y: %f",self.hand.layer.position.y);        }        completion:^(BOol finished) {        }];    }];}];}

所以有什么问题:
当旋转正在进行时,UIVIEw会改变它的center和layer.position属性,这就是为什么我的UIVIEw在动画时会“跳转”.如果关闭自动布局,动画就可以了.我观看了WWDC 2012“按示例自动布局”,发现我会使用[self.hand layoutIfNeeded];一切都很好,但根本不是.动画变得更加平滑,但我看到这种“跳跃”.所以,这是我的“输出”.

当它是动画时,UIVIEw向右移动,就像你在图像上看到的那样,而不是回到正常位置.我怎样才能解决这个“跳跃”问题?

这是一个日志:

layer possition before animation x: 160.000000; y: 99.500000 layer possition after animation 1 x: 197.349030; y: 114.309601 layer possition after animation 2 x: 197.349030; y: 114.309601 layer possition after animation 3 x: 160.000000; y: 99.500000

谢谢.

解决方法 当我布置我的视图时,一切都开始正常工作.进行转换时,重要的是要记住,自动布局总是根据您设置的约束计算视图边界和框架.因此,在我的情况下,我只是将中心垂直和水平对齐,宽度和高度添加到我的旋转视图,因此自动布局机制知道我的视图到底是什么时候.一切都很顺利.这是一个很好的自动布局教程:

http://www.raywenderlich.com/50319/beginning-auto-layout-tutorial-in-ios-7-part-1

总结

以上是内存溢出为你收集整理的ios – Autolayout违反了翻译轮换动画全部内容,希望文章能够帮你解决ios – Autolayout违反了翻译轮换动画所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1076668.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存