每次 Xcode 重新启动时视图错位

Misplaced views each time Xcode restarts(每次 Xcode 重新启动时视图错位)

本文介绍了每次 Xcode 重新启动时视图错位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次在我的应用中使用故事板

I'm using storyboards for the first time in my app

当我关闭 Xcode 时,我收到了 0 个关于错位视图或与我的故事板有关的任何内容的警告.当我重新启动 Xcode 并打开情节提要时,我的 15 个场景中有 3 个有错位的视图警告.

When I close Xcode, I have 0 warnings about misplaced views or anything pertaining to my storyboard. When I restart Xcode and open the storyboard, 3 out of my 15 scenes have misplaced view warnings.

不碰任何东西(除了选择文件),我可以发出一个 git status 并看到 .storyboard 文件发生了变化.如果我 git diff,我会在文件的多个区域看到此内容:

Without touching anything (other than selecting the file), I can issue a git status and see that the .storyboard file has changes. If I git diff, I see this included in multiple areas of the file:

<variation key="widthClass=compact" misplaced="YES">
    <rect key="frame" x="8" y="56" width="130" height="34"/>
</variation>

如果一个元素已经有 <variation key="widthClass=Compact" 节点,则添加 misplaced 属性和 rect 节点.

If an element already had <variation key="widthClass=Compact" node, then the misplaced attribute and rect node are added.

要让警告消失,我唯一要做的就是单击每个警告,确保选中更新框架",然后单击修复错位".在我重新启动 Xcode 之前,这会解决所有问题.

The only thing I have to do to get the warnings to go away is click on each one, make sure "Update Frame" is selected, and click "Fix Misplacement". That fixes everything until I restart Xcode.

我的场景的基本结构是:

The basic structure of my scene is:

UIView
    UICollectionView
        UICollectionReusableView
        UICollectionViewCell
        UICollectionViewCell
    UISegmentedControl

如何防止每次重新启动时发生这种情况?

How can I prevent this from happening each time I restart?

推荐答案

在我的例子中,所有具有自定义字体和固有(未明确定义)大小的标签/按钮都会发生这种情况.看起来像 Xcode 错误.

In my case it happens for all labels / buttons with custom fonts and intrinsic (not explicitly defined) sizes. Looks like an Xcode bug.

这篇关于每次 Xcode 重新启动时视图错位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:每次 Xcode 重新启动时视图错位

基础教程推荐