iOS阻止在某些视图中旋转 [英] iOS prevent rotation in certain views

查看:62
本文介绍了iOS阻止在某些视图中旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个viewcontroller及其视图,仅支持iPad中的横向。

I have a viewcontroller and its view that support only landscape in iPad.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{

if (interfaceOrientation == UIInterfaceOrientationPortrait)
    return NO;
else
    return YES;

}

但我有一个需要的电影播放器​​的视图只是肖像。所以在这个视图中我这样做:

But I have a view with a movie player that needs to be in portrait only. So in this view I do this:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{

if (interfaceOrientation == UIInterfaceOrientationPortrait)
    return YES;
else
    return NO;
}

我的问题是如果我在第一个viewcontroller中将肖像设置为NO,然后我的第二个视图控制器永远不会旋转到肖像。 secondviewcontroller被添加为第一个的子视图。如何让视图1不旋转到纵向,而是使视图2不旋转到横向。这个应用程序是出于演示目的,所以我只是在寻找这个的技术答案。

My problem is that if I, in the first viewcontroller set portrait to NO, then my second view controller will never rotate to portrait. The secondviewcontroller is added as a subview of the first. How can I get view 1 to not rotate to portrait, but get view 2 to not rotate to landscape. This app is for demo purposes so really i'm just looking for the technical answer on this one.

推荐答案

我不相信添加为子视图时可以这样做。尝试将新视图推送到不可见的UINavigationController堆栈以实现您的目标。当从第一个视图到第二个视图时,这将起作用,但是当第二个vc弹出时,让第一个视图将后退旋转到其原始位置是非常棘手的,因为苹果不希望你这样做这个。这是一个非常非常hacky的技巧,强制它回流行:

I do not believe this is possible when adding as a subview. Try pushing the new view onto an invisible UINavigationController stack to accomplish your goal. This will work when going from the first view to the second, but it is very tricky to get the first view to rotate back to its original position when the 2nd vc is popped because apple does not want you doing this. Here's a very very hacky trick to force it back on pop:

-(void)viewDidAppear:(BOOL)animated {   
    UIViewController *c = [[UIViewController alloc] init];
    [self presentModalViewController:c animated:NO];
    [self dismissModalViewControllerAnimated:NO];
    [c release];    
}

这篇关于iOS阻止在某些视图中旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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