Bea*_*red 4 iphone objective-c ios ios8
这是我只想以纵向显示的视图控制器的视图控制器代码...
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
}
- (BOOL)shouldAutorotate {
return NO;
}
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)
这就是我如何呈现它...
MyViewController *myVC = [[MyViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:myVC];
[self presentViewController:nav animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
如果设备处于横向并且呈现视图控制器,它会正确地自动旋转到纵向。但是,如果您在显示设备后旋转设备,它会自动旋转到设备所处的任何方向。我想在显示后防止自动旋转,并仅对这个视图控制器强制纵向方向。这是一个仅限 iOS8 的应用程序。
在此先感谢您的智慧!
问题是您supportedInterfaceOrientations为错误的对象设置了。您已supportedInterfaceOrientations在 MyViewController 中实现。但是看看你的代码:
MyViewController *myVC = [[MyViewController alloc] init];
UINavigationController *nav =
[[UINavigationController alloc] initWithRootViewController:myVC];
[self presentViewController:nav animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
nav是呈现的视图控制器 - 不是 MyViewController。所以nav,UINavigationController 控制着我们是否会旋转——而不是 MyViewController。
所以,给nav一个你实施的委托navigationControllerSupportedInterfaceOrientations:- 一切都会好起来的。
| 归档时间: |
|
| 查看次数: |
5524 次 |
| 最近记录: |