ios的新功能,有一个仪表板屏幕,有许多UIObjects,所以在故事板中创建了一个横向视图控制器。现在我想要现在的纵向视图控制器和横向视图控制器,取决于方向。
有一种称为自动布局和约束的东西,用于为两个方向呈现单个视图控制器
约束有点高级。尝试获取有关自动调整蒙版的一些知识,并将自动布局应用于视图。
自动布局可以减少大量代码。
这里解释得很漂亮。看看这个http://www.raywenderlich.com/50317/beginning-auto-layout-tutorial-in-ios-7-part-1
当然,您可以使用以下代码来执行此操作
if (self.interfaceOrientation == (UIInterfaceOrientationLandscapeLeft) || self.interfaceOrientation == (UIInterfaceOrientationLandscapeRight))
{
//Hide the portrait view and show the Landscape view
[self.Portraitview setHidden:YES];
[self.Landscapeview setHidden:NO];
}
else if (self.interfaceOrientation == UIInterfaceOrientationPortrait)
{
//Show the portrait view and Hide the Landscape view
[self.Portraitview setHidden:NO];
[self.Landscapeview setHidden:YES];
}
一个好的实现方式。
使用单个视图控制器 根据您的设计在基本视图控制器上添加两个UIview。
或
自动布局仅在 iOS 6 及更高版本上可用
https://developer.apple.com/library/ios/documentation/userexperience/conceptual/AutolayoutPG/Introduction/Introduction.html
不要对两个方向使用两个单独的视图,这将导致使用单视图控制器的巨大内存消耗。 始终使用单视图控制器。 如果您不熟悉自动布局,只需记下横向模式下的实际视图框架,然后将其设置为ViewdidLayout或ViewWillLayout方法。