ale*_*clp 3 xcode objective-c uibutton uiviewanimation ios
可能重复:
取消UIView动画?
我有以下动画,我想按下按钮时停止它.你能告诉我我该怎么办?我无法弄清楚如何.谢谢.
-(void)animationLoop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
[UIView beginAnimations:@"Move randomly" context:nil];
[UIView setAnimationDuration:1];
// [UIView setAnimationBeginsFromCurrentState:NO];
CGFloat x = (CGFloat) (arc4random() % (int) self.bounds.size.width);
CGFloat y = (CGFloat) (arc4random() % (int) self.bounds.size.height);
CGPoint squarePostion = CGPointMake(x, y);
strechView.center = squarePostion;
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationLoop:finished:context:)];
[UIView commitAnimations];
}
Run Code Online (Sandbox Code Playgroud)
试试这个:
[myView.layer removeAllAnimations];
Run Code Online (Sandbox Code Playgroud)
并确保也导入Quartz框架:
#import <QuartzCore/QuartzCore.h>
Run Code Online (Sandbox Code Playgroud)
在QuartzCore框架中使用CoreAnimation应用动画,甚至是UIView动画方法.只需定位要停止动画的视图层,然后删除其动画即可.
| 归档时间: |
|
| 查看次数: |
10645 次 |
| 最近记录: |