Question

iPad runs fine for portrait, but not working for Landscape,

I use this code

- (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)];
    }
}

i try to call -(BOOL)isPadLandscape method during debug,but that method not call,

What could be wrong?

Était-ce utile?

La solution

Don't forget to set property Supported interface orientations (iPad) in your Info.plist file for appropriate supported positions.

Or try this:

- (BOOL) isPad{ 
    return [[UIDevice currentDevice].model hasPrefix:@"iPad"];
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top