Fork me on GitHub

setAnimationDidStopSelector如何取消

问:

一个按钮,在点击之前,执行一个改变其透明度的方法

- (void)showButtonAnim {
        ......
        ......
        if(self.button.alpha == 1.0) {
                self.button.alpha = 0.1;
        } else {
                self.button.alpha = 1.0;
        }
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDidStopSelector@selector(showButtonAnim)];
        ......
}

在当前动画结束后就重新调用这个方法

在点击按钮后,想让这个动画不再执行,如何让它停下来呢?

 

答:

1。添加一个BOOL值,为YES时执行动画,为NO时方法直接return,点击按钮后,设置它为NO就行了

 

2。设置[UIView setAnimationDelegate:nil];

 

3。不用其他额外的变量去控制。

就像performSelector方法可以用 

[NSObject cancelPreviousPerformRequestsWithTarget:(id)];

posted on 2012-03-03 20:39  pengyingh  阅读(2822)  评论(0)    收藏  举报

导航