當用戶點擊UIView(全屏)時,我的應用需要檢測方向並執行一些操作。但是有一個小問題。 如果我以橫向模式啓動應用程序,並且用戶點擊背景'interfaceOrientation'變量爲'0',並且我不知道如何重新排列視圖元素。如果我旋轉模擬器一旦一切都很好,但如果不'interfaceOrientation'是'0'。在這裏做什麼?iPad界面方向問題
UIInterfaceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];
if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
...
}
else if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
...
}
else if(interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
...
}
你是從視圖控制器的viewDidLoad調用'[super viewDidLoad]'嗎? – highlycaffeinated
是的,我叫它,但它仍然是'0' – 1110
如果你在你的'viewDidLoad'中向'[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]添加了一個調用,會發生什麼? – highlycaffeinated