我正在创建一个故事书应用程序,它基本上是一系列短动画。每个“翻页”只是页面缩小的简短动画。对于 page1 ,动画按预期工作,但是,对于 page2 ,如果我在第一个动画仍处于进行状态时调用动作页面2,它似乎会跳到正确的位置 page1 就在那一刻,忽略了它自己的持续时间,延迟等。
理想情况下,我希望动画 page2 能够播放,就像它自己的缩小一样,无论何时调用它,我都可以在此代码中更改。
-(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);
一行似乎对 page2 没有影响,因为它没有调整UImageView
的大小,而是似乎从先前的转型中“继承”它的当前大小。
谢谢!
答案 0 :(得分:3)
我实际上并没有弄清楚上面出了什么问题,虽然我已经发现通过使用Core Animation,我确实得到了正确的效果,在每个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"];