旋转呈现的视图并locking呈现视图控制器的方向
我正在研究只支持横向的iPad应用程序,我想让一些提供的视图控制器支持所有的方向而不改变呈现视图控制器的方向。 我支持Xcode设置中的所有方向,除了倒置。
我用来呈现视图控制器的代码
ViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"VC"]; vc.modalPresentationStyle = UIModalPresentationFormSheet; [self presentViewController:vc animated:YES completion:nil];
我正在使用的代码允许呈现视图控制器的方向:
- (UIInterfaceOrientationMask)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAll; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ return YES; }
你pipe应用程序提供同样的function,同时播放video,任何想法如何工作?
任何帮助将不胜感激,谢谢。
AppDelegate.m
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { if(_isAllModes) return UIInterfaceOrientationMaskAll; else return UIInterfaceOrientationMaskPortrait; }
你的ViewController。 回转:
[(AppDelegate*)([UIApplication sharedApplication].delegate) setIsAllModes:YES]; NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait]; [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
我有一个类似的问题,但项目设置覆盖您以编程方式应用单个ViewController设置。 我所做的解决这个问题的方法是在项目设置中保留唯一可接受的方向,并像下面那样在AppDelegate.m中进行扩展
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window //newUX { return UIInterfaceOrientationMaskAll; }
无论如何,你可以做得更好,例如,如果你只想在一个特定的场景中启用所有的方向,只是说最后一个viewController在堆栈里是“全部”一个,就像下面一样
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window //newUX { if([self.navController.viewControllers.lastObject isKindOfClass:[MyAllOrientationVC class]])//newUX return UIInterfaceOrientationMaskAll; else return UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeRight; }