iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – Autolayout违反了翻译轮换动画大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有UIView,我想用旋转动画它.我也想使用autolayout.我已经看到了很多stackoverflow常见问题,但我没有找到任何适用的解决方案.
那么,让我们从我的界面和动画代码开始吧;我有@L_616_4@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向右移动,就像你在图像上看到的那样,而不是回到正常位置.我怎样才能解决这个“跳跃”问题?

这是@L_616_4@日志:

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

谢谢.

解决方法

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

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

大佬总结

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

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。