从仅横向视图返回到纵向应用 [英] Returning from only landscape view to portrait app

查看:99
本文介绍了从仅横向视图返回到纵向应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个仅适用于纵向模式的应用程序,但是,有一个视图需要同时支持纵向和横向模式.每当我从该视图返回时,其余的应用程序就会混乱.

I have an app that works only in portrait mode, however, there is one view that needs to support both portrait as well as landscape mode. Anytime I return from this view the rest of app mess up.

需要同时支持两个方向的视图包含用于播放实时流的网络视图.

The view that needs to support both orientations contains webview that is used to play live stream.

简单的设置应该不起作用.呈现模态视图控制器的窍门都不是.删除和插入根视图的技巧不起作用.

Simple setting shouldAutorotateToInterfaceOrientation doesn't work. The trick with presenting modal view controller neither. The trick with removing and inserting root view doesn't work as well.

恐怕要使用[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait](实际上有效),因为它是私有api.

I am afraid to use [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait] (that actually works) as it is private api.

推荐答案

//
//  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

这篇关于从仅横向视图返回到纵向应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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