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

ios - 滚动时 UIBezierPath 问题的舍入


                                            <p><p>我是 iOS 新手。我正在制作一个聊天应用程序。我正在使用 <code>UITableView</code> 来显示消息聊天(一个单元格 - 一个消息)。<br/>
在每个单元格中,我会在 2,3 或 4 角中将消息四舍五入(如 Facebook 聊天)</p>

<p>对于圆形,我在每个 <code>Tableview Cell</code></p> 的 <code>layoutSubView</code> 内使用 <code>UIBezierPath</code>

<pre><code>UIBezierPath *maskPath = ;

CAShapeLayer *maskLayer = [ init];
maskLayer.frame = self.bounds;
maskLayer.path= maskPath.CGPath;
self.messageView.layer.mask = maskLayer;
</code></pre>

<p> <a href="/image/wuL6V.png" rel="noreferrer noopener nofollow"><img src="/image/wuL6V.png" alt="enter image description here"/></a> </p>

<p><strong>问题是</strong>,当布局第一次初始化时,一切正常,但是当我滚动某些单元格时出现错误的圆角(我发现问题是有时滚动 <code>self.messageView.bounds </code> 返回错误的值,所以 <code>UIBezierPath</code> 绘制了错误的角)但我不知道为什么</p>

<p>我怎样才能防止它发生?
或者我是否可以在没有 <code>UIBezierPath</code> 的情况下使用另一种方法来舍入 View (我谷歌但我只找到一种舍入 UIView 的方法是使用 <code>UIBezierPath</code> :( )?<br/>
任何帮助将不胜感激</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我遇到了类似的问题,并通过在 <code>tableView:willDisplayCell:forRowAtIndexPath</code> 中移动我的圆角代码来解决它。这将允许 Cocoa 正确调整大小。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 滚动时 UIBezierPath 问题的舍入,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/36420899/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/36420899/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 滚动时 UIBezierPath 问题的舍入