我正在创建一个故事书应用程序,它本质上是一系列短片动画。每个“翻页”只是一个页面缩小的短动画。对于page1,动画按预期工作,但是,对于page2,如果我在第一个动画仍在进行时调用 Action page2,它似乎会跳到正确的位置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
的大小,而是似乎从之前的转换中“继承”了它的当前大小。
谢谢!
最佳答案
我实际上还没有弄清楚上面出了什么问题,尽管我已经发现通过使用核心动画,通过在每个 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"];
关于ios - CGAffineTransformScale 和动画未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7458460/