只从风景视图返回到肖像应用程序

我有一个应用程序,只能在肖像模式,但是,有一个视图,需要支持肖像以及风景模式。 任何时候我从这个视图返回应用程序的其余部分搞砸了。

需要支持两个方向的视图包含用于播放直播的webview。

简单的设置shouldAutorotateToInterfaceOrientation不起作用。 呈现模态视图控制器的伎俩既不。 删除和插入根视图的技巧也不起作用。

我害怕使用[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait](实际工作),因为它是私人API。

我有一个应用程序,所有工作在纵向方向,只有一个全屏幕照片支持景观方向。 所以我以模态方式呈现这个全屏视图,并在我的FullscreenViewController.m中

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return ([[UIApplication sharedApplication] statusBarOrientation]); } 

希望这可以是有用的

您可以在viewWillAppear:viewDidAppear:使用[[UIDevice currentDevice] setOrientation:orientation]来强制应用程序旋转到所需的方向。 但是,这是私人电话,不知道苹果是否会批准你的应用程序:)(我的批准)。 祝你好运!

实际上这里提到的删除和插入窗口视图的第一个视图的方法是行不通的! iOS纵向只有横向UIWebview YouTube的应用程序返回

我只是需要从某种原因不要求窗口子视图中的第一个视图。 我需要自己提供根视图。

所以我的解决scheme是在视图控制器中实现以下两种方向的方法:

 -(void)viewWillAppear:(BOOL)animated { m_b_avoid_landscape_orinetation = NO; [super viewWillAppear:animated]; } -(void)viewWillDisappear:(BOOL)animated { m_b_avoid_landscape_orinetation = YES; UIWindow *window = [[UIApplication sharedApplication] keyWindow]; [[self getTabBar].view removeFromSuperview]; [window addSubview:[self getTabBar].view]; [super viewWillDisappear:animated]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { if (m_b_avoid_landscape_orinetation) return (toInterfaceOrientation == UIInterfaceOrientationPortrait); else return YES; } 

其中[self getTabBar]提供了我的自定义选项卡栏,作为窗口子视图中的第一个视图。

编辑所以在iOS 6中不能工作了。 我用插入和删除模式对话框的解决scheme,与其他地方提到的新的supportedInterfaceOrientations方法。

 -(void)goBack { m_b_avoid_landscpae_orinetation = YES; UIViewController *viewController = [[UIViewController alloc] init]; UIWindow *window = [[UIApplication sharedApplication] keyWindow]; [window.rootViewController presentViewController:viewController animated:NO completion:^{ [viewController dismissModalViewControllerAnimated:NO]; }]; [self.navigationController popViewControllerAnimated:YES]; } -(NSUInteger)supportedInterfaceOrientations { if (m_b_avoid_landscpae_orinetation) return UIInterfaceOrientationMaskPortrait; return UIInterfaceOrientationMaskAllButUpsideDown; } 
 // // ViewController.h // CustomNavigationController // // Created by Durul Dalkanat on 11/05/15. // Copyright (c) 2015 Durul Dalkanat. All rights reserved. // #import <UIKit/UIKit.h> @interface ViewController : UIViewController - (IBAction)showLandscapeViewButtonClicked:(id)sender; @end // // ViewController.m // CustomNavigationController // // Created by Durul Dalkanat on 11/05/15. // Copyright (c) 2015 Durul Dalkanat. All rights reserved. // #import "ViewController.h" #import "LandscapeView.h" #import "CustomNavigationControllerViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (IBAction)showLandscapeViewButtonClicked:(id)sender { LandscapeView *landscape = [[LandscapeView alloc]initWithNibName:@"LandscapeView" bundle:nil]; CustomNavigationControllerViewController *nav = [[CustomNavigationControllerViewController alloc]initWithRootViewController:landscape]; nav.navigationBarHidden = true; [self presentViewController:nav animated:YES completion:^{ }]; } #pragma mark handeling rotation - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{ return UIInterfaceOrientationPortrait; } - (BOOL)shouldAutorotate { return NO; } - (NSUInteger)supportedInterfaceOrientations { BOOL atLeastIOS6 = [[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0; if(atLeastIOS6) { return UIInterfaceOrientationMaskPortrait; } else{ return UIInterfaceOrientationPortrait; } } @end And Insert a New ViewController with Xib. After please change freeform. // // LandscapeView.h // CustomNavigationController // // Created by Durul Dalkanat on 11/05/15. // Copyright (c) 2015 Durul Dalkanat. All rights reserved. // #import <UIKit/UIKit.h> @interface LandscapeView : UIViewController @end // // LandscapeView.m // CustomNavigationController // // Created by Durul Dalkanat on 11/05/15. // Copyright (c) 2015 Durul Dalkanat. All rights reserved. // #import "LandscapeView.h" @interface LandscapeView () @end @implementation LandscapeView - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end // // CustomNavigationControllerViewController.m // // // Created by Durul Dalkanat // #import <UIKit/UIKit.h> @interface CustomNavigationControllerViewController : UINavigationController @end // // CustomNavigationControllerViewController.m // // // Created by Durul Dalkanat // #import "CustomNavigationControllerViewController.h" @interface CustomNavigationControllerViewController () @end @implementation CustomNavigationControllerViewController - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscape; } @end