按钮点击时如何暂停和恢复uiview动画?

时间:2013-04-08 05:04:53

标签: iphone ios objective-c uiview uiviewanimation

我有scrollview,其uiview内的缩放属性属性开始animation,它在一段时间内动画效果很好,但在这些animations之间,我想暂停animation {1}}并继续animation,请帮助我解决此问题

[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];

1 个答案:

答案 0 :(得分: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替换为您用于创建动画的方法的名称。