2012-10-05 82 views
0

我有一个只能在纵向模式下工作的应用程序,但是,有一个视图需要同时支持纵向和横向模式。任何时候,我从这个视图返回应用程序的其余部分搞砸了。仅从横向视图返回到纵向应用程序

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

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

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

回答

0

我有一个应用程序,所有的纵向工作,只有一个视图与全屏照片支持横向方向。所以我提出这个观点全屏模态,并在我的FullscreenViewController.m

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

希望这可能是有用的

+0

我也许错过了一些东西。当我呈现视图控制器modaly(与presentModalViewController :)它不会旋转,无论是在shouldAutorotateToInterfaceOrientation: – Engeor

+0

我使用故事板,这里是我如何呈现我的视图控制器,它在上面的代码是它的作品好。 'UIStoryboard * storyboard = self.storyboard; FullScreenPhoto * fullScreen = [storyboard instantiateViewControllerWithIdentifier:@“full”]; //我的图像视图设置 [self presentModalViewController:fullScreen animated:YES]; ' – Pitono

+0

哦,我还是不使用故事板。无论如何,谢谢你的努力。 – Engeor

0

实际上删除和插入这里提到不工作的窗口视图第一视图的方法! iOS portrait only app returns from UIWebview youtube in landscape

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

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

-(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; 
} 

其中[自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; 
} 
0

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

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 
相关问题