ios - CAShapeLayer 动画 iOS7 的问题
<p><p>我一直在努力解决 iOS7 上的动画效果(8、9 效果很好),它涉及将圆角矩形收缩成圆形。得到这样的效果。</p>
<p> <a href="/image/KBayD.gif" rel="noreferrer noopener nofollow"><img src="/image/KBayD.gif" alt="Desired Effect"/></a> </p>
<p>但我在 iOS7 上尝试收缩圆圈时出现了一些失真。</p>
<p> <a href="/image/Xe94b.gif" rel="noreferrer noopener nofollow"><img src="/image/Xe94b.gif" alt="Distorted Effect on iOS7"/></a> </p>
<p>我的 ViewController 非常简单</p>
<pre><code>- (void)viewDidLoad {
;
// Do any additional setup after loading the view, typically from a nib.
CAShapeLayer *layer = ;
layer.fillColor = .CGColor;
layer.frame = CGRectMake(100, 100, 100, 100);
layer.path = .CGPath;
self.myLayer = layer;
;
}
- (void)viewDidAppear:(BOOL)animated {
;
CAKeyframeAnimation *animation = ;
animation.values = @[
(id).CGPath,
(id).CGPath,
(id).CGPath,
(id).CGPath,
(id).CGPath,
(id).CGPath,
];
animation.keyTimes = @[@(0),
@(0.18),
@(0.36),
@(0.54),
@(0.72),
@(1),
];
animation.duration = 10;
animation.fillMode = kCAFillModeForwards;
;
self.myLayer.path = .CGPath;
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>这似乎是 iOS 7 的一个错误。查看此链接:</p>
<p> <a href="http://www.paintcodeapp.com/blogpost/code-for-ios-7-rounded-rectangles" rel="noreferrer noopener nofollow">http://www.paintcodeapp.com/blogpost/code-for-ios-7-rounded-rectangles</a> </p>
<p>帖子底部有一个类别方法可以解决此问题。
我用你的代码测试了它,它似乎工作!我不得不做一个小改动,那就是替换</p>
<pre><code>CGFloat limitedRadius = MIN(radius, limit);
</code></pre>
<p>与</p>
<pre><code>CGFloat limitedRadius = radius;
</code></pre>
<p>这使得拐角半径变得足够大以创建一个圆。可能值得调查一下为什么拐角半径一开始就受到限制,但我会把它留给你 :) </p></p>
<p style="font-size: 20px;">关于ios - CAShapeLayer 动画 iOS7 的问题,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/33648955/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/33648955/
</a>
</p>
页:
[1]