繁体   English   中英

使用UINavigationController iOS 6弹回到初始viewcontroller时,方向会发生变化

[英]Orientation changes when pop back to the initial viewcontroller using UINavigationController iOS 6

我有一个导航控制器,其中根视图控制器i,e。 横向和纵向方向均支持VC1。 当我在横向推动另一个视图控制器i时,e。 VC2只支持纵向模式,回到VC1,视图将变为纵向。 但我仍然处于横向模式。 请帮我解决iOS 6问题。

请检查以下代码。

MyViewController1 *theController =[[MyViewController1 alloc] init];
UINavigationController *navCntlr = [[UINavigationController alloc]      initWithRootViewController:theController];
[self.navigationController presentViewController:navCntlr animated:YES completion:nil];           [theController release];
[navCntlr release];

在MyViewController1中

-(BOOL)shouldAutorotate
{
    return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
    return  UIInterfaceOrientationMaskAllButUpsideDown;
}

在VC2 / MyViewController2中,我添加了以下代码。

-(BOOL)shouldAutorotate
{
    return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
    return  UIInterfaceOrientationMaskPortrait;
}

我也已经将根导航栏子类化了。

实际上这被认为是IOS6中的一个错误发生在ImageViewController上,它只支持Portrait方向...所以我花了很多时间并找到了相同的方法....

希望这有助于首先......

在AppDelegate.h中添加一个属性

@property BOOL model;

然后在AppDelegate.m中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    self.model=NO;

    return YES;
}

也在AppDelegate.m中添加此方法

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{

    if(!self.model)
        return  UIInterfaceOrientationMaskLandscape; //or needed orientation
    else

        return UIInterfaceOrientationMaskAllButUpsideDown;


}

然后在你的视图控制器中呈现VC2之前

实现此代码......

AppDelegate *appdelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
            appdelegate.model=YES;

然后你只需更改VC2的viewWillDisappear中的值

AppDelegate *appdelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
            appdelegate.model=NO;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM