0

我有一个只能在纵向模式下工作的应用程序,但是,有一个视图需要同时支持纵向和横向模式。每当我从这个视图返回时,应用程序的其余部分就会一团糟。

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

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

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

4

4 回答 4

0

我有一个应用程序可以在纵向上运行,只有一个带有全屏照片的视图支持横向。所以我以模态方式在我的 FullscreenViewController.m 中呈现这个全屏视图

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

希望这会有用

于 2012-10-05T08:18:32.743 回答
0

您可以使用[[UIDevice currentDevice] setOrientation:orientation]inviewWillAppear:viewDidAppear:强制应用旋转到所需的方向。但是,这是私人电话,不确定 Apple 是否会批准您的应用程序 :)(我的应用程序已获得批准)。祝你好运!

于 2012-10-05T09:20:30.833 回答
0

实际上,这里提到的删除和插入窗口视图的第一个视图的方法确实有效! 仅 iOS 纵向应用程序从 UIWebview youtube 以横向返回

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

所以我的解决方案是在支持两个方向的视图控制器中实现以下方法:

-(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,它不再起作用了。我使用了插入和删除模态对话框的解决方案,如其他地方提到的新的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;
}
于 2012-10-05T09:00:53.363 回答
0
//
//  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
于 2015-06-12T20:57:55.303 回答