简体   繁体   English

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

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

I have a presented a navigation controller, in which the root view controller i,e. 我有一个导航控制器,其中根视图控制器i,e。 VC1 is supported for both landscape & portrait orientations. 横向和纵向方向均支持VC1。 When i push another view controller in landscape the i,e. 当我在横向推动另一个视图控制器i时,e。 VC2 which supports only portrait mode, come back to the VC1, the view will be turned to portrait. VC2只支持纵向模式,回到VC1,视图将变为纵向。 But i am still in the landscape mode. 但我仍然处于横向模式。 Please help me to solve this on iOS 6 issue. 请帮我解决iOS 6问题。

Please check the below code. 请检查以下代码。

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

in MyViewController1 在MyViewController1中

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

in VC2/MyViewController2 i have added the below code. 在VC2 / MyViewController2中,我添加了以下代码。

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

i have subclassed the root navigation bar as well. 我也已经将根导航栏子类化了。

Actually this was identified as a bug in IOS6 happens with ImageViewController which only supports Portrait orientation ... so i spent lot of time and found a way around the same.... 实际上这被认为是IOS6中的一个错误发生在ImageViewController上,它只支持Portrait方向...所以我花了很多时间并找到了相同的方法....

hope this helps so first things first... 希望这有助于首先......

add a property in your AppDelegate.h 在AppDelegate.h中添加一个属性

@property BOOL model;

then in AppDelegate.m 然后在AppDelegate.m中

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

    return YES;
}

also add this method in AppDelegate.m 也在AppDelegate.m中添加此方法

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

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

        return UIInterfaceOrientationMaskAllButUpsideDown;


}

then in your view controller before presenting the VC2 然后在你的视图控制器中呈现VC2之前

implement this code... 实现此代码......

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

and then you just change the value in the viewWillDisappear of VC2 然后你只需更改VC2的viewWillDisappear中的值

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

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

相关问题 iOS 部分视图控制器在方向改变时变黑 - iOS part of viewcontroller goes black when orientation changes UINavigationController中的ViewController方向更改 - ViewController in UINavigationController orientation change 使用 UITabBarController 而不是 UINavigationController 时返回上一个 ViewController - Return to previous ViewController when using UITabBarController but not UINavigationController iOS:UINavigationController中的锁定方向 - IOS: lock orientation in a UINavigationController 为什么ViewController的初始方向应该是不应该是横向的? - Why is ViewController's initial orientation is not landscape when it should be? UINavigationController pop重置根视图控制器的框架 - UINavigationController pop resets frame of root viewcontroller UINavigationController:弹出 ViewController Animation 暂停一会儿 - UINavigationController: Pop ViewController Animation pause for a while 弹出到 ios 中的下一个 viewController - Pop to next viewController in ios 来回选择时锁定的ViewController方向断开 - Locked ViewController orientation breaking when segueing back and forth iOS - 在父UINavigationController中弹出一个视图 - iOS - pop a view in the parent UINavigationController
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM