ios 更新到 Xcode 8 后的布局问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39497572/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 10:08:57  来源:igfitidea点击:

Layout issues after updating to Xcode 8

iosxcodeautolayoutxcode8ios10

提问by user2726072

Here is a before and after of one of my screens after I upgraded to Xcode 8.
All I did was open up my main.storyboardand from there, I built and ran my app on my phone.
In my version control, I can see Xcode is doing a lot of changes to my main.storyboard just from me opening it.
Whenever I delete those changes, I can see what I use to see in Xcode 7.3.1.
But, as soon as I re-open interface builder with my storyboard, I see those changes come back into place.

Is there something I can do here?

这是升级到 Xcode 8 后我的一个屏幕的前后对比
我所做的只是打开我的main.storyboard,然后我在手机上构建并运行我的应用程序。
在我的版本控制中,我可以看到 Xcode 对我的 main.storyboard 做了很多更改,我打开它。
每当我删除这些更改时,我都可以看到我在 Xcode 7.3.1 中看到的内容。
但是,一旦我用我的故事板重新打开界面构建器,我就会看到这些更改又恢复原状。

有什么我可以在这里做的吗?

Before Xcode 8

Xcode 8 之前

enter image description here

在此处输入图片说明

After update to Xcode 8

更新到 Xcode 8 后

enter image description here

在此处输入图片说明

回答by David T

I had a similar problem with tableview images not appearing once I converted the storyboard file to be Xcode8 compatible. This looks like a bug with Xcode8, so until a bug fix is released, here is a work around:

一旦我将故事板文件转换为与 Xcode8 兼容,tableview 图像就没有出现类似的问题。这看起来像是 Xcode8 的一个错误,所以在发布错误修复之前,这里有一个解决方法:

  1. Open your storyboard in Xcode 8 and choose an initial device view. Make changes as you normally would.
  2. Once you have completed your changes, select the storyboard -> File Inspector -> Opens in -> Select 'Xcode 7.x'.
  1. 在 Xcode 8 中打开您的故事板并选择一个初始设备视图。像往常一样进行更改。
  2. 完成更改后,选择 storyboard -> File Inspector -> Opens in -> Select 'Xcode 7.x'。

enter image description here

在此处输入图片说明

  1. Select 'Save and Close' when prompted
  2. Your storyboard changes will be saved, and your storyboard will function as it did pre-Xcode8.
  1. 出现提示时选择“保存并关闭”
  2. 您的故事板更改将被保存,您的故事板将像在 Xcode8 之前一样发挥作用。

When you need to make other changes to the storyboard file, follow these steps again.

当您需要对情节提要文件进行其他更改时,请再次执行这些步骤。

回答by Bhavesh Kumbhani

XIB or Storyboard set default as older version 7.x and Save and Close. Temporary solution, but works. Don't open again once you have done Save and Close. Otherwise again need follow same steps from begin.enter image description here

XIB 或 Storyboard 将默认设置为旧版本 7.x 并保存并关闭。临时解决方案,但有效。完成保存并关闭后不要再次打开。否则再次需要从头开始执行相同的步骤。在此处输入图片说明

回答by TekMi

Eh the same problem. I partially managed to fix it in the following way (for Xcode Version 8.1 (8B62))

嗯同样的问题。我部分设法通过以下方式修复它(对于 Xcode 版本 8.1 (8B62)

In the document outline of Storyboard, I clicked on each scene which had the yellow arrow indicating some layout issues (Number 1 on the screenshot)

在 Storyboard 的文档大纲中,我点击了每个场景,其中黄色箭头表示一些布局问题(屏幕截图中的数字 1)

After this, for each problematic scene, I had to click on "Update Frames" small icon (Number 2 on the screenshot) which fixed all the layout issues per scene.

在此之后,对于每个有问题的场景,我必须单击“更新帧”小图标(屏幕截图上的数字 2),它修复了每个场景的所有布局问题。

enter image description here

在此处输入图片说明

However one scene in my case was still in crying state after transition from Xcode7 to Xcode8. I had to fix it manually by adjusting constraints or adding missing constraints.

然而,我的一个场景在从 Xcode7 转换到 Xcode8 后仍然处于哭泣状态。我不得不通过调整约束或添加缺少的约束来手动修复它。

Phew, not nice surprise of XCode8 and Storyboards. If you used AppCode editor, you won't have such problem, since it doesn't support Storyboards ;P

呼,XCode8 和 Storyboards 不是什么惊喜。如果您使用 AppCode 编辑器,则不会有这样的问题,因为它不支持 Storyboards ;P

Good luck!

祝你好运!

回答by Maniganda saravanan

Xcode 8.1 Beta 2 resolves this issue. Please check this download link

Xcode 8.1 Beta 2 解决了这个问题。请检查此下载链接

https://developer.apple.com/download/

https://developer.apple.com/download/

回答by Mike.R

Please follow the threads for any possible solution:(I believe it happens to many developers).
Xcode 8 GM seed Storyboard issue
Xcode 8 - Previous storyboards getting distorted

(I used anyH anyW width 600) When Xcode updated to Xcode 8 it changed all my ViewControllers size. As a result all the layout was distorted.
Currently I see only 3 solution for the issue (I wouldn't trust on waiting for fix soon).

请按照线程获取任何可能的解决方案:(我相信许多开发人员都会遇到这种情况)。
Xcode 8 GM 种子故事板问题
Xcode 8 - 以前的故事板变得扭曲

(我使用 anyH anyW 宽度 600) 当 Xcode 更新到 Xcode 8 时,它更改了我所有的 ViewControllers 大小。结果,所有的布局都被扭曲了。
目前我只看到 3 种解决方案(我不相信很快就会等待修复)。

1.Go for each Viewcontroller and fix it it by Update Frames.

2.Go to the main ViewController Size Inspector -> Freeform -> 600as most of the controllers are inferred it will change the size for all of them.(Be careful on the impact of new Features Apple my want to introduce).

3.Discard the changes in git for the storyboard (I would't suggest it because Apple also inserted some updates which may be important to Xcode).

1.为每个Viewcontroller寻找并修复它Update Frames

2.转到主视图Size Inspector -> Freeform -> 600控制器,因为大多数控制器都被推断出它会改变所有控制器的大小。(小心我想介绍的苹果新功能的影响)。

3.丢弃故事板的git更改(我不建议这样做,因为Apple还插入了一些对Xcode可能很重要的更新)。

Additional link for the new AutoLayout features in Xcode 8 (WWDC16): Making Apps Adaptive, Part 1

Xcode 8 (WWDC16) 中新自动布局功能的附加链接: 使应用程序自适应,第 1 部分

回答by christian mini

In my case works solutions suggested by Akhil Kateja and I also need to reset Width and Height of the main view:

在我的情况下,Akhil Kateja 建议的解决方案我还需要重置主视图的宽度和高度:

1) Set View Size to Free Form

1) 将视图大小设置为自由形式

enter image description here

在此处输入图片说明

2) Reset Width and Height of the view to the original size:

2)将视图的宽度和高度重置为原始大小:

enter image description here

在此处输入图片说明

Finally save and you are done.

最后保存,你就完成了。

回答by whycodewhyyyy

For me the solution was simply to click on the UIViewController having issues and then Editor > Resolve Auto Layout Issues > All Views In ... > Updates Frames

对我来说,解决方案只是点击有问题的 UIViewController 然后 Editor > Resolve Auto Layout Issues > All Views In ... > Updates Frames

It re-arranged the views to fit the existing constraints based on the newly selected default view (iPhone 7 in my case).

它根据新选择的默认视图(在我的情况下为 iPhone 7)重新排列视图以适应现有约束。

Also note: if you get a Navigation Bar Misplaced Viewwarning like I did, simply select the UINavigationController/UIViewController and then Attributes Inspector > Bar Visibility > Shows Navigation Bar- toggle it OFF and then ON again.

另请注意:如果您像我一样收到Navigation Bar Misplaced View警告,只需选择 UINavigationController/UIViewController 然后Attributes Inspector > Bar Visibility > Shows Navigation Bar- 将其关闭,然后再次打开。

回答by goe

The answer from @david-truong (https://stackoverflow.com/a/39589860/1407528) is not working in my case, so if you are in my same situation, try this:

@david-truong ( https://stackoverflow.com/a/39589860/1407528)的答案在我的情况下不起作用,所以如果你处于同样的情况,试试这个:

In the case you have all your devices updated to iOS 10+, this version of Xcode will not recognize those devices as compatible devices. So, try with this trick:

如果您将所有设备都更新到 iOS 10+,此版本的 Xcode 将无法将这些设备识别为兼容设备。所以,试试这个技巧:

  • Go to: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
  • Copy the folders related with iOS 10 or 10.1 to: /Applications/Xcode 7.3.1.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
  • Open the project with Xcode 7.3.1 (restart Xcode if you have it already opened)
  • Select your connected iOS 10+ device
  • Push Run
  • 转到:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
  • 将与 iOS 10 或 10.1 相关的文件夹复制到:/Applications/Xcode 7.3.1.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
  • 使用 Xcode 7.3.1 打开项目(如果已经打开,请重新启动 Xcode)
  • 选择您连接的 iOS 10+ 设备
  • 推跑

Note: New features like Swift will not be available using this trick, but you should be able to load and build your project.

注意:使用此技巧将无法使用 Swift 等新功能,但您应该能够加载和构建您的项目。

回答by Anurag Bhakuni

Hope this will help

希望这会有所帮助

When i updated Xcode from 7.3 to Xcode 8 and run the app, some of the views are perfectly displayed but some are distorted.Then, i checked the nib file and it prompted me to choose particular device size and then show the nib according to that device size which is offcourse not Any-Any(Xcode 7.3). So all the nibs file are not displaying in a correct way.

当我将 Xcode 从 7.3 更新到 Xcode 8 并运行应用程序时,一些视图完美显示,但有些视图失真。然后,我检查了笔尖文件,它提示我选择特定的设备尺寸,然后根据该文件显示笔尖设备尺寸当然不是Any-Any(Xcode 7.3)。所以所有的 nibs 文件都没有以正确的方式显示。

Solution work form me :- press the yellow arrow like showing in image below

解决方案工作形成我:-按下黄色箭头,如下图所示

enter image description here

在此处输入图片说明

it will prompt a pop up which show options like

它会提示一个弹出窗口,其中显示了类似的选项

enter image description here

在此处输入图片说明

choose Update Frameswith Apply to all views in containerchecked.it will solved around 90% of distorted UI and rest of the auto-layout constraints problem can be solved manually.

选择Update FramesApply to all views in containerchecked.it将围绕扭曲UI的90%,解决和休息的自动布局约束问题可以手动解决。

回答by Mayckon Barbosa

I selected each controller and clicked on "Update Frames" and it fixed the layout.

我选择了每个控制器并单击“更新框架”并修复了布局。