简体   繁体   English

iPhone 6 Plus自动旋转问题

[英]iPhone 6 Plus Autorotation Issue

I'm running into a strange autorotation issue on iPhone 6 plus only (simulator and actual device). 我仅在iPhone 6 plus(模拟器和实际设备)上遇到一个奇怪的自动旋转问题。

I have created a fresh Xcode project with a single view. 我用一个视图创建了一个新的Xcode项目。 And all it has is some UI elements in the initial view controller (with proper constraints). 它所具有的只是初始视图控制器中的一些UI元素(具有适当的约束)。 Here's what it looks like on the initial launch: 这是首次启动时的样子:

在此处输入图片说明

But once, I change the device orientation, all UI elements disappear?!?! 但是一旦更改了设备方向,所有UI元素就会消失?!?!

在此处输入图片说明

This does not happen on any other devices. 在其他任何设备上都不会发生这种情况。

What am I missing here? 我在这里想念什么? Really appreciate your help. 非常感谢您的帮助。

Regarding the original question: your size class of the auto layout constraints seems to be wrong. 关于原始问题:自动布局约束的大小类似乎是错误的。 That would cause your view to be rendered in one width/height combination just fine and would completely fail in another. 那将导致您的视图以一种宽度/高度组合很好地呈现,而在另一种宽度/高度组合中完全失败。 Designing in any size class other than any/any will result in a blue size class bar at the bottom of Xcode indicating / warning about that. 除任何/任何以外的任何尺寸类别的设计都会在Xcode的底部显示一个蓝色尺寸类别栏,以指示/警告有关这一点。

In general you should specify constraints for every supported size classes. 通常,您应该为每个受支持的尺寸类别指定约束。 The easiest way is to just design your view in the any/any class. 最简单的方法是仅在任何/任何类中设计视图。 That way your layout will be the same on all configurations. 这样,您的布局在所有配置上都将相同。 You can alter the specified constraints for just one size class as well be just selecting that size class and inspecting a view´s constraints, enable/disable them or add new ones. 您可以只为一个尺寸类别更改指定的约束,也可以仅选择该尺寸类别并检查视图的约束,启用/禁用它们或添加新的约束。 Those will only be set in that specific size class. 这些将仅在该特定尺寸等级中设置。 To view a constraint you can either select it in the storyboard or double click on it in the size inspector of the view it belongs to. 要查看约束,可以在情节提要中选择它,也可以在它所属的视图的大小检查器中双击它。 The last section in the size inspector of the constraint tells in what size classes it exists. 约束的大小检查器的最后一部分说明了约束存在的大小类。

约束的大小类设置示例

To migrate a view from one size class to another would just mean to change this size class on every view and constraint... 将视图从一个尺寸类别迁移到另一个尺寸类别意味着在每个视图和约束上更改此尺寸类别...

Manual way 手动方式
To do that you need to add the size class you want to migrate to by pressing the + next to the Installed checkbox and click on the little x on the left of the size class you want to migrate from. 为此,您需要通过单击Installed复选框旁边的+来添加要迁移到的尺寸类别,然后单击要从其迁移的尺寸类别左侧的小x If you want to migrate to any/any, don't click on the + , just tick the checkbox next to Installed . 如果要迁移到任何一个,请不要单击+ ,只需选中Installed旁边的复选框。 And do not forget to change the size class on the view object itself as well. 而且不要忘记改变大小类视图对象本身也是如此。 If you do not do that the view will just not be present in the desired size class. 如果您不这样做,则视图将不会出现在所需的尺寸级别中。

Automatic way 自动方式
This is possible to be changed viewing the source code of the Storyboard file as well. 也可以通过查看Storyboard文件的源代码来更改此设置。 A constraint setup might look like this 约束设置可能看起来像这样

<variation key="default">
    <mask key="subviews">
        <exclude reference="fTD-HZ-ZT3"/>
    </mask>
    <mask key="constraints">
        <exclude reference="eyr-oK-LvV"/>
    </mask>
</variation>
<variation key="heightClass=compact-widthClass=regular">
    <mask key="subviews">
        <include reference="fTD-HZ-ZT3"/>
    </mask>
    <mask key="constraints">
        <include reference="eyr-oK-LvV"/>
    </mask>
</variation>

The key attribute in the variation item apparently specifies the size class. 变化项中的key属性显然指定了大小类。 Default meaning any/any. Default表示任意/任意。 It would be a lot easier to just search and replace all occurrences of the size class you want to migrate from with the size class you want to migrate to. 仅搜索并替换所有要迁移的大小类,然后将其替换为要迁移的大小类会容易得多。 If you are migrating from or to the default class it is a little bit trickier since you have to change exclude to include and vice versa. 如果要从默认类迁移或迁移到默认类,则有点棘手,因为您必须更改excludeinclude ,反之亦然。 You then would have to add / remove the complete size class section you are migrating to/from. 然后,您将不得不添加/删除要迁移到/从中迁移的完整大小类部分。 Little bit more work, but still a lot easier than doing it by hand. 工作多一点,但比手工完成要容易得多。
You should be careful however if your view already contains size class specifications for multiple size classes to change only the correct ones. 但是,如果您的视图已包含多个尺寸类别的尺寸类别规范以仅更改正确的尺寸类别,则应小心。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM