0

我有,它在beginscrollview里面有 zoomscale 属性,它在一段时间内动画效果很好,但在这之间我想暂停并恢复,请帮我解决这个问题uiviewanimationanimationsanimationanimation

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

1 回答 1

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 替换为您用于创建动画的方法的名称。

于 2013-04-08T05:17:31.420 回答