Objective c StatusBaroOrientation不';我不能给出正确的答案
当按下按钮时,我正在检查设备是否处于横向模式或纵向模式,并显示以下代码:Objective c StatusBaroOrientation不';我不能给出正确的答案,objective-c,Objective C,当按下按钮时,我正在检查设备是否处于横向模式或纵向模式,并显示以下代码: orientation = [[UIApplication sharedApplication]statusBarOrientation]; - (void)buttonclick { if (orientation == UIInterfaceOrientationPortrait) { NSLog(@"port"); } else { NSLog
orientation = [[UIApplication sharedApplication]statusBarOrientation];
- (void)buttonclick
{
if (orientation == UIInterfaceOrientationPortrait)
{
NSLog(@"port");
}
else
{
NSLog(@"Land");
}
}
在这种情况下,即使模拟器处于纵向模式,它也会记录着陆。怎么了?您应该在方法内部设置方向:
- (void)buttonClick {
orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait)
{
NSLog(@"port");
}
else
{
NSLog(@"Land");
}
}