故事板:当我更改布局约束时,如何让 Xcode 自动更新框架?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25814840/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Storyboard: How do I let Xcode automatically update frames when I change layout constraints?
提问by Tom van Zummeren
I have seen a WWDC 2014 video (What's new in Interface Builder) where the presenter uses Storyboard and changes the height of a table view cell prototype within a table view controller (at around 7m30s). I see all the subviews of that cell resize as he drags the height-handle on the cell. This is great, because now you can see how your layout constraints behave in different scenarios very quickly.
我看过一个 WWDC 2014 视频(Interface Builder 中的新增功能),其中演示者使用 Storyboard 并更改表视图控制器中表视图单元格原型的高度(大约 7 分 30 秒)。当他拖动单元格上的高度手柄时,我看到该单元格的所有子视图都调整了大小。这很棒,因为现在您可以非常快速地看到布局约束在不同场景中的表现。
He doesn't explain how he does it. Because when I drag the height-handle of a table view cell prototype, the frames of all my subviews don't update. They only update when I select from the menu: Editor > Resolve Auto Layout Issues > Update Frames (All Views in Table View Controller)
他没有解释他是如何做到的。因为当我拖动表格视图单元格原型的高度手柄时,所有子视图的框架都不会更新。它们仅在我从菜单中选择时更新:编辑器 > 解决自动布局问题 > 更新框架(表视图控制器中的所有视图)
Is there an Xcode setting anywhere that toggles live-updating the view frames I see in Storyboard, obeying the layout constraints?
是否有任何 Xcode 设置可以切换实时更新我在 Storyboard 中看到的视图框架,遵守布局约束?
采纳答案by rob mayoff
In theory, you should be able to turn on “Descendants”?in the “Resizing Behavior” popup menu (lower-right corner of the storyboard editor).
理论上,您应该能够在“调整大小行为”弹出菜单(故事板编辑器的右下角)中打开“后代”?
In practice, it's broken in your case. I have the same problem. You can report the bug at http://bugreport.apple.com/.
在实践中,它在你的情况下被破坏了。我也有同样的问题。您可以在http://bugreport.apple.com/报告错误。
Possibly it works better in Yosemite. I'm still running Mavericks.
可能它在优胜美地效果更好。我还在跑小牛队。
回答by Vlad
Update: On XCode 8 Beta 5 I tested and found XIB where I needed to manually update Frame now automatically updates when I resize freeform view.
更新:在 XCode 8 Beta 5 上,我测试并发现需要手动更新 Frame 的 XIB 现在会在我调整自由形式视图大小时自动更新。
On XCode 7.3.1: This is not solution but I find a good compromise.
在 XCode 7.3.1 上:这不是解决方案,但我找到了一个很好的折衷方案。
Go to XCode -> Preferences -> Key Bindings -> Search for "Update Frames". Remove existing shortcuts for the first item (which does not seem to work) and replace the shortcut to CTRL+OPTION+COMMAND+P for the second item. The shortcut is an example, you can add whatever shortcut you want that does not conflict with existing bindings).
转到 XCode -> 首选项 -> 键绑定 -> 搜索“更新帧”。删除第一项的现有快捷方式(似乎不起作用)并将第二项的快捷方式替换为 CTRL+OPTION+COMMAND+P。快捷方式是一个示例,您可以添加任何您想要的与现有绑定不冲突的快捷方式)。
Now each time you resize you can quickly use the shortcut to update the frame.
现在,每次调整大小时,您都可以快速使用快捷方式来更新框架。
回答by JamWils
The correct answer is marked that it is a bug, but it might be the case that Interface Builder cannot make sense of your constraints to auto update them. I'm using Xcode 6.2 on Yosemite. I thought I had the same issue, but as my constraints have become more complete, Interface Builder is updating them as I go.
正确答案标记为它是一个错误,但可能是 Interface Builder 无法理解您的约束来自动更新它们。我在优胜美地使用 Xcode 6.2。我以为我遇到了同样的问题,但随着我的约束变得更加完整,Interface Builder 正在更新它们。