我有一个导航控制器,可以将用户带到另一个视图,并根据用户点击的按钮和方向布置新视图。我有一个名为layout
的方法,我在viewDidLoad
,viewWillAppear
和willAnimateRotationToInterfaceOrientation
但是,首次加载视图时,应用程序无法在横向中识别它。我的代码是:
UILabel *shareLabel = [[UILabel alloc] initWithFrame:CGRectMake(488, 90, 179, 30)];
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)) {
shareLabel.frame = CGRectMake(543, 90, 238, 30);
}
我甚至尝试在if语句上设置一个断点,当它到达if语句时,它会跳过它,这告诉我它没有意识到它是风景?关于为什么会这样的任何想法?
答案 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
}