Xcode方向属性不返回当前方向

时间:2012-08-14 05:52:25

标签: iphone xcode button orientation hide

我想在设备向右旋转时禁用按钮myButton。我设置了一个if块以在旋转时隐藏按钮,但设备无法识别它已被旋转。当我运行模拟并旋转模拟器时,我的NSLog语句显示为false。为什么要这样做?

UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
NSLog(orientation == UIInterfaceOrientationLandscapeLeft?@"true":@"false");

if([[UIDevice currentDevice] orientation]  == UIInterfaceOrientationLandscapeLeft)
{
   [myButton setHidden:YES];
}

1 个答案:

答案 0 :(得分:2)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft )
{
     [myButton setHidden:YES];
}

return interfaceOrientation;
}
祝你好运....