2011-09-17 73 views
2

我正在创建一个故事书应用程序,它基本上就像一系列短动画。每个“翻页”只是页面缩小的简短动画。对于page1,动画按预期工作,但是,如果我在第一个动画仍在进行中时调用动作page2,则它似乎跳入正确的位置,忽略它的当前位置自己的时间,延迟等CGAffineTransformScale和动画按预期工作

理想情况下,我想动画第2页发挥,因为它是自己的缩小,以同样的方式,无论何时它被称为,什么可能我在此代码更改。

-(IBAction) page1 
{ 
    pageImageNext.bounds = CGRectMake(-240, -370, 1200, 800); 

    [UIImageView animateWithDuration:7.5 delay:2.0 options: UIViewAnimationOptionOverrideInheritedDuration | 
                  UIViewAnimationOptionAllowUserInteraction animations:^{ 
     CGAffineTransform zoom = CGAffineTransformScale(CGAffineTransformIdentity, .4, .4); 
     self.pageImageNext.center = CGPointMake(240,160); 
     self.pageImageNext.transform = zoom; 

    } completion:^(BOOL finished) {}]; 
} 

-(IBAction) page2 
{ 
    pageImageNext.image = [UIImage imageNamed:@"page2.jpg"]; 
    pageImageNext.bounds = CGRectMake(-240, -370, 1200, 800); 

    [UIImageView animateWithDuration:7.5 delay:6.0 options: UIViewAnimationOptionOverrideInheritedDuration | 
                  UIViewAnimationOptionAllowUserInteraction | 
                  UIViewAnimationOptionBeginFromCurrentState animations: ^{ 
     CGAffineTransform zoom2 = CGAffineTransformScale(CGAffineTransformIdentity, .4, .4);  
     self.pageImageNext.center = CGPointMake(240,160); 
     self.pageImageNext.transform = zoom2; 

    } completion:^(BOOL finished) {}]; 
} 

另外行pageImageNext.bounds = CGRectMake(-240, -370, 1200, 800);似乎已经第2页没有影响,因为它是不调整的UImageView,而是似乎“继承”这是从先前的变换电流的大小。

谢谢!

回答

3

我没有真正想通了什么在上面走错了,虽然我已经想通了,通过使用核心动画,我得到正确的效果,通过在每个IBAction使用此代码:

pageImageNext.image = [UIImage imageNamed:@"page1.jpg"]; 
pageImageNext.bounds = CGRectMake(-240, -470, 1200, 800); 

CABasicAnimation *zoomOut = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; 
zoomOut.beginTime = CACurrentMediaTime()+4; 
zoomOut.toValue = [NSNumber numberWithDouble:0.4]; 
zoomOut.duration = 8.0; 
zoomOut.fillMode=kCAFillModeForwards; 
zoomOut.removedOnCompletion=NO; 
[pageImageNext.layer addAnimation:zoomOut forKey:@"zoomOut"];