您可以使用自動佈局來提供縱向和橫向模式。
有關更多詳細信息,請檢查: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