ios - CGAffineTransformScale 和动画未按预期工作
<p><p>我正在创建一个故事书应用程序,它本质上是一系列短动画。每个“翻页”只是页面缩小的一个简短动画。对于 <strong>page1</strong>,动画按预期工作,但是,对于 <strong>page2</strong>,如果我在第一个动画仍在进行时调用操作 page2,它似乎会跳到正确的位置<strong>page1</strong> 在那个时刻,忽略它自己的持续时间、延迟等。</p>
<p>理想情况下,我希望动画 <strong>page2</strong> 以自己的缩小方式播放,同样的方式,无论何时调用,我都可以在此代码中进行哪些更改。</p>
<pre><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 = ;
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) {}];
}
</code></pre>
<p>另外 <strong><code>pageImageNext.bounds = CGRectMake(-240, -370, 1200, 800);</code></strong> 行似乎在 <strong>page2</strong>,因为它没有调整 <code>UImageView</code> 的大小,而是似乎从之前的转换“继承”了它的当前大小。</p>
<p>谢谢!</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我实际上并没有弄清楚上面出了什么问题,尽管我发现通过使用 Core Animation,我确实得到了正确的效果,通过在每个 <code>IBAction</code> 中使用此代码:</p>
<pre><code>pageImageNext.image = ;
pageImageNext.bounds = CGRectMake(-240, -470, 1200, 800);
CABasicAnimation *zoomOut = ;
zoomOut.beginTime = CACurrentMediaTime()+4;
zoomOut.toValue = ;
zoomOut.duration = 8.0;
zoomOut.fillMode=kCAFillModeForwards;
zoomOut.removedOnCompletion=NO;
;
</code></pre></p>
<p style="font-size: 20px;">关于ios - CGAffineTransformScale 和动画未按预期工作,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/7458460/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/7458460/
</a>
</p>
页:
[1]