iphone - iOS 阻止某些 View 中的旋转

标签 iphone ios ipad

我有一个 View Controller 及其 View ,仅支持 iPad 中的横向。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{

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

}

但我有一个电影播放器​​的 View ,只需要纵向显示。所以在这个 View 中我这样做:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{

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

我的问题是,如果我在第一个 View Controller 中将纵向设置为“否”,那么我的第二个 View Controller 将永远不会旋转到纵向。第二个 View Controller 被添加为第一个 View Controller 的 subview 。如何使 View 1 不旋转为纵向,但使 View 2 不旋转为横向。该应用程序用于演示目的,因此我实际上只是在寻找有关此应用程序的技术答案。

最佳答案

我认为添加为 subview 时这是不可能的。尝试将新 View 推送到不可见的 UINavigationController 堆栈上以实现您的目标。当从第一个 View 转到第二个 View 时,这将起作用,但是当弹出第二个 vc 时,让第一个 View 旋转回原来的位置是非常棘手的,因为苹果不希望你这样做这。这是一个非常非常黑的技巧,可以强制它回到流行状态:

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

关于iphone - iOS 阻止某些 View 中的旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7196300/

相关文章:

iphone - 旋转:我收到错误 "wait_fences: failed to receive reply: 10004003"

ios - 使用 CIImage- Swift 的二维码生成器

ios - 如何打开包含UIview或图像的弹出窗口

iphone - 解析 OBJ 文件

objective-c - 在 NSMutableArray 中使用 plist 时出错

ios - FileProvider: "CopyItem()"被调用两次 -> 错误(FTP 下载)

ios - Cordova 8 + iOS 4.5.4 = 找不到模块 "../cordova/platform_metadata"

iphone - 如何在 iPad/iPhone 中编辑(添加或删除).ipa 文件的内容

iphone - 在 iPhone 上调试 applicationDidReceiveMemoryWarning 的最佳方法?

iphone - 如何将 UISlider 的值显示为整数