如何在appdelegate上查看横向和纵向模式?

Ank*_*han 2 iphone cocoa-touch objective-c ios4

我想在横向和纵向模式下运行应用程序,

如何在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));

}
Run Code Online (Sandbox Code Playgroud)

但是在appdelegate类型的对象上找不到错误属性界面方向.

我怎样才能做到这一点?

Par*_*att 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
}
Run Code Online (Sandbox Code Playgroud)

我希望这可以帮助你.:)

如果您需要任何帮助,请随时与我联系.