菜鸟教程小白 发表于 2022-12-11 17:35:36

ios - Xcode 8 GM 破坏了我的 UI


                                            <p><p>啊。选择初始设备 View (6s)后,我所有的边界都完全搞砸了。我使用了以下代码:</p>

<pre><code>func roundButtonLeft(button: UIButton) {

    let path = UIBezierPath(roundedRect:button.bounds, byRoundingCorners:[.topLeft, .bottomLeft], cornerRadii: CGSize(width: 10, height: 10))
    let maskLayer = CAShapeLayer()
    maskLayer.path = path.cgPath

    let frameLayer = CAShapeLayer()
    frameLayer.path = path.cgPath
    frameLayer.lineWidth = 1.0
    frameLayer.strokeColor = UIColor.white.cgColor
    frameLayer.fillColor = nil

    button.layer.addSublayer(frameLayer)
    button.layer.mask = maskLayer}
</code></pre>

<p>在我的 UI 按钮的一侧添加了边框。这现在根本不起作用,白色边框从屏幕上射出。 </p>

<p>如果我放弃我的更改,它会在我打开 Storyboard 并被迫选择初始设备之前正常工作。 </p>

<p>有人可以帮忙吗?我已经为此浪费了几个晚上。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>这花了很长时间才弄清楚。但它与 button.bounds 有关。</p>

<p>我通过添加来修复它:</p>

<pre><code>button.layoutIfNeeded()
</code></pre>

<p>在添加子层之前。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - Xcode 8 GM 破坏了我的 UI,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/39604641/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/39604641/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - Xcode 8 GM 破坏了我的 UI