旋转呈现视图并锁定呈现视图控制器的方向

2024-03-31

我正在开发仅支持横向方向的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;
}

You Tube 应用程序在播放视频时提供相同类型的功能,您知道它是如何工作的吗?

任何帮助将不胜感激,谢谢。


AppDelegate.m

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {

if(_isAllModes)
    return UIInterfaceOrientationMaskAll;
else
    return UIInterfaceOrientationMaskPortrait;
}

你的视图控制器。回转:

[(AppDelegate*)([UIApplication sharedApplication].delegate) setIsAllModes:YES];
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

旋转呈现视图并锁定呈现视图控制器的方向 的相关文章

随机推荐