簡體   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