UIView animateWithDuration仅动画一次

Mor*_*pps 2 iphone animation uiimageview ios

我已经设置了一个动画块,以便在用户执行搜索时启动.搜索完成后,将推送新视图.这工作正常,直到用户选择后退按钮并再次尝试搜索,现在动画无法启动.

[UIView animateWithDuration:0.25
                      delay:0.0
                    options:(UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveLinear)
                 animations:^{

                     _collectionImage.transform = CGAffineTransformMakeRotation(M_PI);

                 }
                 completion:^(BOOL finished){
                     NSLog(@"Done!");
                 }];
Run Code Online (Sandbox Code Playgroud)

在任何人询问之前,动画只是旋转的光盘,并且在推入视图加载时调用完成块.任何有关为什么它不会在多次搜索中制作动画的帮助将不胜感激.

谢谢.

Aru*_*run 5

嗨这是你的问题......

你将仿射值x改为y

所以现在你的变换值是y然后你的等于y = y

然后它是如何工作的....

最初,您需要存储转换值,然后在完成需要恢复值的动画后为其设置动画

viewDidLoad这样做:

initalTransform=_collectionImage.transform;


[UIView animateWithDuration:0.25
                      delay:0.0
                    options:(UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveLinear)
                 animations:^{

                     _collectionImage.transform = CGAffineTransformMakeRotation(M_PI);

                 }
                 completion:^(BOOL finished){
                     NSLog(@"Done!");
_collectionImage.transform=initalTransform;
                 }];
Run Code Online (Sandbox Code Playgroud)

尝试这个....这是一个你需要实现作为你的逻辑的想法......