您可以使用自动布局来提供纵向和横向模式。
有关更多详细信息,请检查:What is Auto Layout?。
您必须设置横向和纵向模式的约束条件才能正常工作。就像如果你想在顶部有一个按钮一样,你可以在它上面设置约束:从顶部到左边等等。
如果您希望UI元素的工作动态更改,您只需根据需要更改方向上的框架即可。示例代码是在这里:
# pragma mark - Orientation related methods
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration NS_AVAILABLE_IOS(3_0)
{
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
[self deviceRotatedToLandscapeMode];
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
[self deviceRotatedToLandscapeMode];
}
else if (toInterfaceOrientation == UIInterfaceOrientationPortrait) {
[self deviceRotatedToPortraitMode];
}
else if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
[self deviceRotatedToPortraitMode];
}
}
- (void) deviceRotatedToPortraitMode {
self.mTableView.frame = CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height);
}
- (void) deviceRotatedToLandscapeMode {
self.mTableView.frame = CGRectMake(0.0, 0.0, self.view.frame.size.height, self.view.frame.size.height);
}
使用自动尺寸面膜或者你可以去HTTP - 在您的视图控制器创建的方法。com/50319 /开始自动布局教程在ios-7-part-2 – morroko