重复UIAnimation块,以及再次停止它的方法

Ric*_*kiG 3 cocoa-touch core-animation uiviewanimation ios4 objective-c-blocks

我想做一个小的装载动画来放入我的应用程序.我之前用CGAnimations做过重复动画没有问题,这次我想采用块方法.

我正在做一个小测试,但可以重复以下代码:

- (void) startLoading {

    __block int count = 0;

    [UIView animateWithDuration:0.4
                          delay: 0.0
                        options: UIViewAnimationOptionRepeat
                     animations:^{
                         count++;
                     }
                     completion:^(BOOL finished){

                         if (count > 5)
                             count = 0;
                         NSLog(@"%d", count);

                     }];

}

- (void) stopLoading {

}
Run Code Online (Sandbox Code Playgroud)

以上仅触发完成块一次,不重复.

如何让块重复以使计数递增?

如果我得到这个工作并将我的动画放入重复块, 什么进入stopLoading:再次停止动画?

谢谢你给予的任何帮助:)

mat*_*att 5

这是一个有限的重复动画:

- (void) animate: (int) count {
    CGPoint origC = v.center;
    void (^anim) (void) = ^{
        v.center = CGPointMake(100,100);
    };    
    void (^after) (BOOL) = ^(BOOL finished) {
        v.center = origC;
        if (count)
            [self animate:count-1];
    };
    int opts = UIViewAnimationOptionAutoreverse;
    [UIView animateWithDuration:1 delay:0 options:opts 
                     animations:anim completion:after];
}
Run Code Online (Sandbox Code Playgroud)

这里有一个递归,所以我们不想过火或者我们的内存不足,但是如果我们限制我们的数量(在你的例子中它是5)我们应该没问题.