我只在一个视图控制器的横向模式下使用以下代码
- (BOOL)shouldAutorotate {
return NO;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationLandscapeRight; // or Right of course
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
工作正常但是当我旋转到肖像然后它正在旋转并且我使用下面的代码来呈现视图
[self presentViewController:vc animated:YES completion:nil];
我提前错过了
答案 0 :(得分:0)
使用此代码
在AppDelegate.h
@property (assign, nonatomic) BOOL shouldRotate;
AppDelegate.m
BOOL shouldRotate;
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
if (self.shouldRotate)
return UIInterfaceOrientationMaskAllButUpsideDown;
else
return UIInterfaceOrientationMaskPortrait;
}
现在打开要在其中应用方向的ViewController并使用此代码
AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate setShouldRotate:YES]; // set NO to disable rotation