如何停止的UIView动画 [英] How to stop an UIView animation
本文介绍了如何停止的UIView动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有几个的UIImageViews
中的的UIScrollView
,我想扭动,当用户长期presses其中之一。因此,类似的行为你当你长期preSS在您的iPad / iPhone菜单的图标。
所以,我有以下几点:
- (无效){startWiggling 对于(*的UIImageView中的TouchView [滚动视图的子视图]){ [UIView的beginAnimations:@摆动背景:无];
[UIView的setAnimationDuration:0.1];
[UIView的setAnimationRepeatAutoreverses:YES];
[UIView的setAnimationRepeatCount:FLT_MAX]; //摆动1度两面
touchView.transform = CGAffineTransformMakeRotation();
touchView.transform = CGAffineTransformMakeRotation(-0.0174532925); [UIView的commitAnimations]; }} - (无效){stopWiggling
的NSLog(@停止摆动);
}
这工作正常。问题是...我怎样才能使它的停止扭动用户之后pressed一个按钮?我有一个按钮,并将其连接等,它是达到 stopWiggling
方法,所以这是很好。但如此...
- 如何从这些
的UIImageViews
? 删除动画的UIView - 我可以绑定这一行动给用户pressing其设备上的主页按钮?
解决方案
#进口< QuartzCore / QuartzCore.h>
然后
[myView.layer removeAllAnimations]
或
[self.view.layer removeAllAnimations]
I have several UIImageViews
within a UIScrollView
that I want to wiggle when the user long-presses one of them. So similar to the behavior you get when you long-press an icon in your iPad/iPhone menu.
So I have the following:
- (void)startWiggling {
for (UIImageView *touchView in [scrollView subviews]) {
[UIView beginAnimations:@"wiggle" context:nil];
[UIView setAnimationDuration:0.1];
[UIView setAnimationRepeatAutoreverses:YES];
[UIView setAnimationRepeatCount:FLT_MAX];
//wiggle 1 degree both sides
touchView.transform = CGAffineTransformMakeRotation();
touchView.transform = CGAffineTransformMakeRotation(-0.0174532925);
[UIView commitAnimations];
}
}
- (void)stopWiggling {
NSLog(@"Stop wiggling");
}
This works fine. The issue is... How can I make it stop wiggling after the user has pressed a button? I have a button and connected it etc and it's reaching the stopWiggling
method, so that's fine. But so...
- How do I remove the UIView animation from these
UIImageViews
? - Can I bind this action to the user pressing the home button on their device?
解决方案
#import <QuartzCore/QuartzCore.h>
then
[myView.layer removeAllAnimations];
or
[self.view.layer removeAllAnimations];
这篇关于如何停止的UIView动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文