2011-09-05 100 views
2

我想在橫向和縱向模式下運行應用程序,如何檢查appdelegate上的橫向和縱向模式?

如何在Appdelegate上檢查橫向和縱向模式?

我打電話

- (BOOL) isPad{ 
#ifdef UI_USER_INTERFACE_IDIOM 
    return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad); 
#else 
    return NO; 
#endif 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    if ([self isPad]) { 
     NSLog(@"is pad method call"); 
     return YES; 
    } 
    else 
    { 
     return UIInterfaceOrientationIsPortrait(interfaceOrientation); 
    } 

} 



- (BOOL)isPadPortrait 
{ 

    return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad 
      && (self.interfaceOrientation == UIInterfaceOrientationPortrait 
       || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)); 
} 


- (BOOL)isPadLandscape 
{ 

    return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad 
      && (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight 
       || self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft)); 

} 

,但給出了類型的appdelegate的對象未找到錯誤 接口屬性定位。

我該怎麼做?

回答

7

你應該檢查你的iPad使用的當前方向。我建議你在每個視圖上檢查這些條件,並根據當前的方向採取行動:

if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft) 
{ 
     //Do what you want in Landscape Left 
} 
else if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight) 
{ 
     //Do what you want in Landscape Right 
} 
else if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait) 
{ 
    //Do what you want in Portrait 
} 
else if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown) 
{ 
     //Do what you want in Portrait Upside Down 
} 

我希望這可以幫助你。 :)

如果您需要任何幫助,請隨時與我聯繫。

+0

@Ankit:這對您有幫助嗎? –

+0

這不適用於appDelegate。在我的情況下,無論方向如何,條件始終是LandscapeRight。 – NightCoder

2
- (void)applicationDidFinishLaunching:(UIApplication *)application { 


    UIDeviceOrientation orientation = [UIDevice currentDevice].orientation; 

    NSString *nibName = UIDeviceOrientationIsLandscape(orientation) ? @"Landscape" : @"Portrait"; 


    NSLog(@"orientation is %@",nibName); 
} 
+0

我已經創建了一個方法 - 上的appdelegate showplayer中,我嘗試檢查橫向和縱向的方法,和所有其他網頁上的我叫-showplayer方法,按照烏拉圭回合的建議,我覺得不能夠給予筆尖每個其他頁面的名稱,是否有任何其他方式來檢查土地景觀肖像? –

+0

如果鋪設單位,設備方向可能會有問題,您應該改用狀態bas orientation我認爲 – NightCoder

1

委託方向是,我們在plist中指定,如果我們不是在plist中方向其指定將採取縱向模式默認。但在委託你只有不適用的重要窗口方向支持你必須添加視圖控制器或任何導航控制器的視圖,然後你可以調用這些功能,他們會給你的設備的正確方向。

2
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
    { 
    if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft || [[UIDevice currentDevice] orientation ]== UIDeviceOrientationLandscapeRight) 
    { 
     NSLog(@"Lanscapse"); 
    } 
    if([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown) 
    { 
     NSLog(@"UIDeviceOrientationPortrait"); 
    } 
    } 
相關問題