本文介绍了在iOS 10下自动调整不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有一个没有AutoLayout和Constraints的应用程序。我只在尺寸检查器中设置自动调整。在iOS 9和更早版本下工作都很好。在iOS 10下,自动调整功能不起作用,并将大小设置在屏幕之外。请看下面的图片:
在模拟器中的iOS 10下

I had a app that works without AutoLayout and Constraints. I only set the autoresizing in the size inspector. Under iOS 9 and earlier works all fine. Under iOS 10 the autoresizing doesn't work and set the size out of the screen. Look at the following picture :Under iOS 10 in the simulator

iPhone 5和iPhone 6 Plus也是如此。我能做些什么,自动调整工作正常。

The same is happened on a iPhone 5 and iPhone 6 Plus. What can I do, that the autoresizing works fine.

编辑1:
另一种解决方法是将故事板设置为Xcode 7.x版本。您可以在 Interface Builder文档下的文件检查器中执行此操作。将打开选项设置为值 Xcode 7.x 。使用保存并关闭回答以下问题。如果您现在在iPad或iPhone上运行该项目,所有具有UIScrollView的视图控制器都可以正常调整大小。

Edit 1:Another workaround is to set the storyboard to Xcode 7.x version. You can do this in the File Inspector under Interface Builder Document. To set the option Opens in to the value Xcode 7.x. Answer the following question with save and close. If you now run the project on your iPad or iPhone all view controller with UIScrollView works fine with the auto resizing.

重要:
此解决方法在每次执行后执行故事板中的变化。

Important:This workaround to perform after each change in the storyboard.

编辑2:我在苹果开发者论坛上发了一个帖子,看看这里:

Edit 2: I had make a cross post in the apple developer forum, look here : https://forums.developer.apple.com/message/182716#182716

推荐答案

首先,进入有问题的故事板,找到有问题的滚动视图,然后在属性中取消选中Autoresize Subviews。这将阻止Xcode自动撤消我们即将要做的所有事情。

First, go into the offending storyboard and find the scrollview in question and in attributes uncheck Autoresize Subviews. This will prevent Xcode from automatically undoing everything we're about to do.

其次,这是一个痛苦的部分,你需要修复视图的宽度。 scrollview并将它们返回到正确的设置。只需单击视图,找到右侧控制旋钮,然后将其拖回滚动视图内。

Second, and this is the painful part, you need to fix the widths of the views in the scrollview and return them to their proper settings. Just click on the view, find the right hand control knobs, and drag it back inside the scroll view.

为了使下一步更容易,所有子视图应该在滚动视图中嵌套的单个内容视图中。 (嵌套内容视图也是在滚动视图中使用自动调整大小自动布局的最佳实践,因此请习惯它。)

In order to make the next step easier, all of the subviews should be in a single content view nested within the scrollview. (The nested content view is also a "best practice" for using auto-sizing auto-layouts in scrollviews, so get used to it.)

请注意,如果你不喜欢它首先取消选中Autoresize Subviews,然后Xcode会在下次重新打开故事板时重新排列所有内容。

Note that if you don't first uncheck Autoresize Subviews then Xcode will kindly rearrange everything again the next time you reopen your storyboard.

第三,您需要在您的滚动视图和内容视图中使用IBOutlets代码。

Third, you need IBOutlets for your scrollview and your content view in your code.

最后,将以下内容添加到ViewController中......

Finally, add the following to your ViewController...

- (void)viewDidLayoutSubviews
{
    [self.scrollView setAutoresizesSubviews:YES];

    CGRect frame = self.contentView.frame;
    frame.size.width = self.view.frame.size.width - 20;
    self.contentView.frame = frame;

    [super viewDidLayoutSubviews];
}

基本上,我们重新启用自动调整大小,然后设置内容视图的宽度是适当的宽度。在这里,我希望我的内容视图嵌套在具有10px边距的滚动视图中(因此为-20)。

Basically, we're reenabling autoresize and then setting the width of the content view to be the proper width. Here, I want my content view to be nested within the scroll view with 10px margins (hence the - 20).

以上需要针对每个违规的scrollview进行故事板。

The above needs to be done for each offending scrollview in the storyboard.

有点参与,只是权宜之计,但比使用自动布局做全新布局要快。我能够在大约15分钟内用大约12个场景和VC来修补故事板。使用自动布局重建所有内容会花费很多很长时间。

A little involved, and just a stopgap measure, but faster than doing a brand new layout using autolayout. I was able to patch up a storyboard with about a dozen scenes and VC's in about 15 minutes. It would have taken much, much, much longer to rebuild everything using auto layout.

请注意,这在最新的Xcode 8.1测试版中也没有修复。我很确定他们知道这个错误,但我也很确定这是Apple鼓励开发人员开始使用自动布局的方式。

Note that this is also NOT fixed in the latest Xcode 8.1 beta. I'm pretty sure they're aware of the bug, but I'm also pretty sure this is Apple's way of "encouraging" their developers to start using auto layout.

这篇关于在iOS 10下自动调整不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 15:31