CGAffineTransformScale 和动画未按预期工作
我正在创建一个故事书应用程序,它本质上是一系列短片动画。每个“翻页”只是一个页面缩小的短动画。对于page1,动画按预期工作,但是,对于page2,如果我在第一个动画仍在进行时调用动作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 的大小,而是似乎从之前的转换中“继承”了它的当前大小。
谢谢!
I am creating a storybook app, which is essentially as series of short animations. Each "page turn" is just a short animation where the page zooms out. For page1, the animation works as expected, however, for page2, if I call the action page2 while the first animation is still in progress, it seems to jump in right where page1 is at that moment, ignoring it's own duration, delay, etc.
Ideally, I'd like the animation page2 to play as it's own zoom out, the same way, no matter when it is called, what might I change in this code.
-(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) {}];
}
In addition the line pageImageNext.bounds = CGRectMake(-240, -370, 1200, 800);
seems to have no effect in page2, as it isn't resizing the UImageView
, but rather seems to "inherit" it's current size from the previous transformation.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我实际上还没有弄清楚上面出了什么问题,尽管我已经发现通过使用核心动画,通过在每个 IBAction 中使用以下代码,我确实获得了正确的效果:
I haven't actually figured out what was going wrong in the above, though I have figured out that by using Core Animation, I do get the correct effect, by using this code in each
IBAction
: