菜鸟教程小白 发表于 2022-12-13 11:19:11

ios - UIView 圆形 mask 动画


                                            <p><p>我有一个抽象的奇怪形状的 UIView。
而且我需要显示一个<strong>平滑</strong>外观动画。 </p>

<p>我假设我应该将该动画应用于该 View 上方的蒙版。
面具将是圆形的。
所以用户将看到 1'2'3'4' 序列。
我该如何实现?
我想我应该应用一些仿射变换
到蒙版 View 。在那种情况下,面具的原始形状应该是什么?
一条竖线? </p>

<p> <a href="/image/15fkb.jpg" rel="noreferrer noopener nofollow"><img src="/image/15fkb.jpg" alt="enter image description here"/></a> </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>一个简单的例子,假设我有一个100*100的<code>imageview</code>,</p>

<p> <img src="/image/L9MMI.gif" width="200"/> </p>

<p><strong>注意:为简单起见,我使用硬编码数字</strong></p>

<pre><code> CAShapeLayer * maskLayer = ;
maskLayer.bounds = CGRectMake(0, 0, 100, 100);
maskLayer.position = CGPointMake(50, 50);
UIBezierPath * path = ;
maskLayer.path = path.CGPath;
maskLayer.fillColor = .CGColor;
maskLayer.strokeColor = .CGColor;
maskLayer.strokeEnd = 0.0;
maskLayer.lineWidth = 100;
self.imageview.layer.mask = maskLayer;

CABasicAnimation * animation = ;
animation.keyPath = @&#34;strokeEnd&#34;;
animation.toValue = @(1.0);
animation.duration = 2.0;
animation.timingFunction = ;
animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = NO;

;
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - UIView 圆形 mask 动画,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/31563353/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/31563353/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - UIView 圆形 mask 动画