不同的横向和纵向设计

Different landscape and portrait design

您好,我的应用程序采用纵向设计,我想在用户旋转设备时更改此设计。

类似的东西:

纵向:

按钮 1 - 按钮 2

按钮 3 - 按钮 4

横向:

按钮 1 - 按钮 2 - 按钮 3 - 按钮 4

不知道下一个方法是不是最好的:

[[NSNotificationCenter defaultCenter] addObserver:self
                       selector:@selector(didRotate:)
                       name:UIDeviceOrientationDidChangeNotification
                       object:nil];
- (void) didRotate:(NSNotification *)notification{
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    if (orientation == UIDeviceOrientationLandscapeLeft)    {
        HERE CHANGE THE CONSTRAINS
    }
}

谢谢大家。

为什么不使用尺寸 classes?大小 class 是应用于任何视图或视图控制器的 属性,表示可以在给定的水平或垂直维度中显示的内容量。自 iOS8 后尺寸 classes 可用。几乎 90% 的设备都使用 iOS8,当然这取决于您的要求。

https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/MobileHIG/LayoutandAppearance.html

如果你想支持旧的iOS版本,你的方法也不错。

You can do this with using Size Class. i did this... 
1. First Desigh Screen in wAny - hAny and set all Constrains
2. For Portrait select wCompact - hRegular and go to Size inspector
3. In Descendant Constrains there are many Constrains select one by one (double click on that)
4. you can see two + button. perss it and select wCompact - hRegular. it shownew field set Constrains (Size). do this for all Constrains.
5. Now for Landscape in storybord select wRegular - hCompact and do this same...

它的工作方式与 if - else if 条件相同... if (Portrait){ this } else if (Landscape) { this }