旋转呈现的视图并锁定呈现视图控制器的方向 [英] Rotate presented view and lock the orientation of presenting view controller

查看:125
本文介绍了旋转呈现的视图并锁定呈现视图控制器的方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发仅支持横向的iPad应用程序,我想允许一些呈现的视图控制器支持所有方向而不改变呈现视图控制器的方向。我支持Xcode设置中的所有方向,除了颠倒。

I am working on iPad application which supports only landscape orientation, i want to allow some presented view controller to support all orientation without changing orientation of presenting view controller. Am supporting all orientation in Xcode Settings except upside down.

我用来呈现视图控制器的代码

Code i am using to present view controller

    ViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"VC"];
    vc.modalPresentationStyle = UIModalPresentationFormSheet;
    [self presentViewController:vc animated:YES completion:nil];

我正在使用的代码允许展示视图控制器的方向:

Code i am using to allowing orientation for presented view controller:

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
    return YES;
}

你管应用在播放视频时提供相同的功能,任何想法如何工作了吗?

You tube app provide same kind of feature while playing video, any idea how it is working?

感谢任何帮助。

推荐答案

我有类似的问题,但项目设置会覆盖您以编程方式应用的单个ViewController设置。我为解决这个问题所做的是在项目设置中留下唯一最小的可接受方向,并在AppDelegate.m中扩展它,如下所示

I had a similar issue, but project settings overwrite single ViewController settings you applied programmatically. What I did to solve the issue was leaving the only min acceptable orientation in project settings and extending it in AppDelegate.m like below

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window //newUX
{
    return UIInterfaceOrientationMaskAll;
}

无论如何你都可以做得更好,例如,如果你想全部启用仅在一个特定场景中定位,只是说堆栈中的最后一个viewController是否为all-one,如下所示

you can do it better anyway, for example, if you want to enable all orientations only in one specific scenario, just saying if last viewController in stack is the "all"-one, like below

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window //newUX
{
    if([self.navController.viewControllers.lastObject isKindOfClass:[MyAllOrientationVC class]])//newUX
        return UIInterfaceOrientationMaskAll;
    else
        return UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeRight;
}

这篇关于旋转呈现的视图并锁定呈现视图控制器的方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆