iOS6.0从横向viewController以纵向方向推入新的viewController [英] iOS6.0 Pushing new viewController in portrait orientation from landscape viewController

查看:74
本文介绍了iOS6.0从横向viewController以纵向方向推入新的viewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序基于导航,并且主要以纵向运行,但是一个视图控制器同时支持纵向和横向.现在的问题是,当我从横向视图控制器中推送新的viewcontroller时,尽管我希望在纵向模式下也将其以横向模式推送.

My application is navigation based and mainly runs in portrait orientation, But one view controller supports both portrait and landscape orientation. Now the problem is, When I push the new viewcontroller from landscape view controller, the new view controller is also pushed in landscape mode though i want it in portrait mode.

另外,当我从横向控制器弹出视图控制器时,弹出的视图控制器将以纵向模式显示.

Also when I pop view controller from landscape controller then the poped view controller is getting displayed in portrait mode.

我不知道我的代码有什么问题.

I don't know what is wrong with my code.

这是我的代码段以及用于这些方向支持的信息.

Here is the my code snippet and information used for these orientation support.

在info.plist文件中,除了纵向倒置外,我一直支持所有方向.

In info.plist file I kept support for all orientation but portrait upsidedown.

我还为导航控制器类别添加了以下类别.

I have also added category for navigation controller category as below.

@implementation UINavigationController(Rotation_IOS6)
-(BOOL)shouldAutorotate
{
    return [[self.viewControllers lastObject] shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations
{
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
@end

我还创建了一个UIViewController子类,该子类充当所有类的超类.这是超类的定向方法.

I have also created a UIViewController subclass that acts as superclass for all classes. Here are the orientation methods for super class.

@implementation ParentViewController

- (BOOL)shouldAutorotate{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
    return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationPortrait;
}
@end

和支持横向的定向方法控制器如下.

And the orientation methods controller that supports landscape are as below.

@implementation LandscapeController
#pragma mark -
#pragma mark Orientation Methods
- (BOOL)shouldAutorotate{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskLandscape;
}

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
    return (toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end

先谢谢了.

推荐答案

这是推送视图的方法.进行对象切换

Here is the method to push the view.take an object switch

在switch.m

+ (void)loadController:(UIViewController*)VControllerToLoad andRelease:(UIViewController*)VControllerToRelease
{

VControllerToLoad.navigationController.navigationBar.frame=CGRectMake(0, 0, 568, 44);
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
CGRect windowFrame = [[UIScreen mainScreen] bounds];
CGRect firstViewFrame = CGRectMake(statusBarFrame.origin.x, statusBarFrame.size.height, windowFrame.size.width, windowFrame.size.height - statusBarFrame.size.height);
VControllerToLoad.view.frame = firstViewFrame;

//check version and go

if (IOS_OLDER_THAN_6)
{
    [((AppDelegate*)[UIApplication sharedApplication].delegate).window addSubview:VControllerToLoad.view];
}
else
{
    [((AppDelegate*)[UIApplication sharedApplication].delegate).window setRootViewController:VControllerToLoad];

}
  [VControllerToRelease.view removeFromSuperview];
}

您可以使用上述方法从横向模式下推送至人像视图

You can push to portrait view from landscape mode like this using above method

 PortraitViewController *portraitVC=[[PortraitViewController alloc]initWithNibName:@"PortraitViewController" bundle:nil];

  [Switch loadController:portraitVC andRelease:self];

在景观视图控制器上.m

At landscape view controller.m

    - (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationController.title=@"Landscape";
    appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    appDelegate.navigationController.navigationBarHidden = NO;
    if (IOS_OLDER_THAN_6)
        [[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationLandscapeLeft animated:NO];
    // Do any additional setup after loading the view from its nib.
}

#ifdef IOS_NEWER_OR_EQUAL_TO_6

-(BOOL)shouldAutorotate  
{
    return YES; 
 }

- (NSUInteger)supportedInterfaceOrientations    
 {
    return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft; 
 }

#endif

这篇关于iOS6.0从横向viewController以纵向方向推入新的viewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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