Приложение ipad не работает в ландшафтном режиме - PullRequest
2 голосов
/ 02 сентября 2011

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 во время отладки, но этот метод не вызывается,

Что может быть не так?

1 Ответ

2 голосов
/ 02 сентября 2011

Не забудьте установить свойство Supported interface orientations (iPad) в файле Info.plist для соответствующих поддерживаемых позиций.

Или попробуйте это:

- (BOOL) isPad{ 
    return [[UIDevice currentDevice].model hasPrefix:@"iPad"];
}
...