开发者

ipad app not works for landscape mode

开发者 https://www.devze.com 2023-04-01 19:29 出处:网络
iPad runs fine for portrait, but not working for Landscape, I use this code - (BOOL) isPad{ #ifdef UI_USER_INTERFACE_IDIOM

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 ([sel开发者_如何学编程f 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?


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"];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号