【问题标题】:Issue on navigation controller while changing the orientation更改方向时导航控制器上的问题
【发布时间】:2011-12-03 10:29:35
【问题描述】:

我有两个视图控制器,其中我使用导航控制器从一个视图导航到另一个视图..... 在我的第一个视图控制器中,我在- (void)viewDidLoad 中以这种方式检查方向

if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
{
//Do this task
}
else
{
//Do this task
}

当我试图从第二个视图控制器导航到第一个视图控制器时.. 我正在使用此代码导航

-(IBAction)back
{
    [self.navigationController popViewControllerAnimated:YES];

}

问题来了…… 未检查上述方向条件..当我试图从第二个视图控制器导航到第一个视图控制器时...... 我不知道我在哪里落后了......我是否坚持任何逻辑或者我想更改我的代码???????

【问题讨论】:

    标签: iphone uinavigationcontroller orientation


    【解决方案1】:

    调用这个方法

        -(void) viewWillAppear:(BOOL)animated{
    
    
            [self willAnimateRotationToInterfaceOrientation:[UIApplication sharedApplication].statusBarOrientation duration:0]; 
        }
    
    
    -(void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
    {
        if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown )
        {
    
        set frame here........  
        }
        else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight )
        {
        set frame here........          
    
        }
    
    
    
    }
    

    【讨论】:

    • 这里需要这个方法是什么?我想在哪里调用这个
    • 是的,我知道只有在设备方向发生变化时才调用此方法
    • 当你调用 popViewControllerAnimated 方法时 viewdidLoad 方法当时没有调用 viewWillAppear 方法所以当时你调用了 Rotaion 方法。
    猜你喜欢
    • 1970-01-01
    • 2015-07-12
    • 2012-06-11
    • 1970-01-01
    • 1970-01-01
    • 2017-11-15
    相关资源
    最近更新 更多