2013-04-08 147 views
0

我有scrollview,其中有zoomscale物业内uiview开始animation,它以动画以及一些时间,但在这些animations之间我想暂停animation和恢复animation,请帮我出这个如何在点击按钮时暂停和恢复uiview动画?

[UIView beginAnimations:@"anim1" context:NULL]; 
[UIView setAnimationDelegate:self]; 
[UIView setAnimationDuration:fanim]; 
z = [[arrImage1 objectAtIndex:1] floatValue]; 
scroll.zoomScale = z; 
NSLog(@" %f",scroll.zoomScale); 
if (iw != 0 || ih != 0) 
{ 
    image1.frame = CGRectMake(0, 0, iw,ih); 
} 
z = [[arrImage2 objectAtIndex:1] floatValue]; 
scroll1.zoomScale = z; 
z = [[arrImage3 objectAtIndex:1] floatValue]; 
scroll2.zoomScale = z; 
[UIView commitAnimations]; 
+0

你可以参考以下几点: http://stackoverflow.com/questions/3211065/how-to-pause-and-resume-uiview-animation 和 HTTP:/ /stackoverflow.com/questions/9104487/how-to-pause-and-resume-uiview-animation-without-block-animation – 2013-04-08 05:16:23

回答

0

这可以通过使用nstimer。尝试使用nstimer来启动和暂停动画,这里是一组您可以使用的代码。在方法中实现动画和使用的NSTimer火灾,并暂停:

- (void)viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:animated]; 
    [self startTimer]; 
} 

- (void)viewWillDisappear:(BOOL)animated { 
    [super viewWillDisappear:animated]; 
    [self stopTimer]; 
} 

- (void)startTimer { 
    NSTimer *timer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:3.0] interval:3.0 target:self selector:@selector(this is where your animation method name goest) userInfo:nil repeats:YES]; 
    [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]; 
    self.animationmethodename = timer; 
    [timer release]; 
} 

- (void)stopTimer { 
    [self.animationmethodname invalidate]; 
    self.animationmethodtimer = nil; 
} 

然后与你使用的是创建动画的方法的名称替换animationmethodname。

+0

可以请你告诉什么是动画方法? – 2013-04-08 05:41:01

+0

你的意思是startTimer方法? – 2013-04-08 05:42:27

+0

动画方法名称是用于实现您在问题中显示的代码的方法。我想你可能会把这一套代码放在viewdidload中,如果是这样,那么你可以删除它并创建一个 - (void)方法,并且之后放置的任何名称都将替代animationmethodname。 – 2013-04-08 05:46:20