简体   繁体   中英

iPhone 6 Plus Autorotation Issue

I'm running into a strange autorotation issue on iPhone 6 plus only (simulator and actual device).

I have created a fresh Xcode project with a single view. And all it has is some UI elements in the initial view controller (with proper constraints). Here's what it looks like on the initial launch:

在此处输入图片说明

But once, I change the device orientation, all UI elements disappear?!?!

在此处输入图片说明

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.

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. If you want to migrate to any/any, don't click on the + , just tick the checkbox next to 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. 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. Default meaning any/any. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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