2013-04-08 144 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