【发布时间】:2011-07-09 14:49:55
【问题描述】:
当用户点击 UIView(全屏)时,我的应用需要检测方向并执行一些操作。但是有一个小问题。 如果我以横向模式启动应用程序并且用户点击背景“interfaceOrientation”变量为“0”并且我不知道如何重新排列视图元素。如果我在一切正常后旋转模拟器,但如果不是,则“interfaceOrientation”为“0”。在这里做什么?
UIInterfaceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];
if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
...
}
else if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
...
}
else if(interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
...
}
【问题讨论】:
-
您是从视图控制器的
viewDidLoad调用[super viewDidLoad]吗? -
是的,我称之为,但它仍然是 '0'
-
如果您在
viewDidLoad中添加对[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]的调用会怎样?
标签: iphone objective-c ios ipad ios4