首次加载ios时无法识别横向

时间:2014-01-27 10:49:47

标签: ios objective-c landscape

我有一个导航控制器,可以将用户带到另一个视图,并根据用户点击的按钮和方向布置新视图。我有一个名为layout的方法,我在viewDidLoadviewWillAppearwillAnimateRotationToInterfaceOrientation

中调用此方法

但是,首次加载视图时,应用程序无法在横向中识别它。我的代码是:

UILabel *shareLabel = [[UILabel alloc] initWithFrame:CGRectMake(488, 90, 179, 30)];
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)) {
    shareLabel.frame = CGRectMake(543, 90, 238, 30);
}

我甚至尝试在if语句上设置一个断点,当它到达if语句时,它会跳过它,这告诉我它没有意识到它是风景?关于为什么会这样的任何想法?

1 个答案:

答案 0 :(得分:0)

检查出来

 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

if ( ([[UIDevice currentDevice] orientation] ==  UIDeviceOrientationPortrait)  )
{
// do something for Portrait mode
}
else if(([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight) ||          ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeLeft))
{
// do something for Landscape mode
}