2013-02-20 44 views
0

我是檢查設備和接口方向programetically但每次它甚至在portraite模式轉爲橫向也 這裏是我的代碼,請給我解決方案: -iPad的定位檢查錯誤

if ([[UIDevice currentDevice]orientation] == UIDeviceOrientationLandscapeLeft||[[UIDevice currentDevice] orientation]== UIDeviceOrientationLandscapeRight || [self interfaceOrientation] == UIInterfaceOrientationLandscapeLeft || [self interfaceOrientation] == UIInterfaceOrientationLandscapeRight) 
    { 

    } 
    else 
    { 


    } 

回答

0

始終使用

 if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait) 
    { 
    //orientation is portrait 
    } 

    if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight) 
    { 
    //orientation is landscape 
    } 
0
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 

if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait) ) 
{ 
    //Portrait coding 
} 
else if(([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight) ||   [[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeLeft)) 
{ 
//Landscape coding 
}