我已经搜索过这个论坛(和其他论坛),但尚未找到解决方案。 我有一个横向模式的应用程序。一切都很好,但是当我更改为另一个 View (使用 UITable)时,它处于纵向模式并且不会旋转。我已经尝试了一整天,但无法弄清楚。
@property (nonatomic, strong) IBOutlet UIView *aView;
@property (nonatomic, strong) IBOutlet UIViewController *aViewcontroller;
-----
aViewcontroller = [[UIViewController alloc] initWithNibName:@"ViewController" bundle:nil];
aViewcontroller.view = aView;
-----
[self presentModalViewController:aViewcontroller animated:YES];
//got my view in portrait orientation.
我的 .xib 文件中的 View 全部设置为方向:横向。 这应该很简单吧?
先谢谢了!
最佳答案
默认情况下,UIViewController 仅支持纵向。为了支持其他方向,您需要创建新的自定义 View Controller 来支持您需要的方向。
步骤:
创建新的自定义 View Controller ViewControllerLandscape
然后将其导入到您的 mainn View Controller
#import "ViewControllerLandscape.h"
更改您的代码:
aViewcontroller = [[ViewControllerLandscape alloc] initWithNibName:@"ViewController" bundle:nil];
aViewcontroller.view = aView;
[self presentModalViewController:aViewcontroller animated:YES];
在您的ViewControllerLandscape
中添加方法:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) ||
(interfaceOrientation == UIInterfaceOrientationLandscapeRight)) {
return YES;
}
return NO;
}
关于xcode - 横向呈现ModalViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11670539/