2

iPad 在纵向上运行良好,但不适用于横向,

我使用此代码

- (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]) {

        return YES;
    }
    else 
    {
        return UIInterfaceOrientationIsPortrait(interfaceOrientation);
    }

}


- (BOOL)isPadLandscape
{

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

}

- (BOOL)isPadPortrait
{

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




- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if ([self isPadPortrait])
    {
        [imageView setFrame:CGRectMake(0, -50, 768, 1024)];        
    }
    else if ([self isPadLandscape])
    {
        [imageView setFrame:CGRectMake(0, 0, 1024, 768)];
    }
}

我尝试在调试期间调用 -(BOOL)isPadLandscape 方法,但该方法没有调用,

有什么问题?

4

1 回答 1

2

不要忘记Supported interface orientations (iPad)在 Info.plist 文件中为适当的支持位置设置属性。

或者试试这个:

- (BOOL) isPad{ 
    return [[UIDevice currentDevice].model hasPrefix:@"iPad"];
}
于 2011-09-02T12:13:48.017 回答