UIScreen mainScreen bounds.size.height always 1024

jdog picture jdog · Oct 10, 2012 · Viewed 13.2k times · Source

Why would [UIScreen mainScreen].bounds.size.height always return 1024 no matter what layout mode the iPad app is in?

I am trying to have a custom view dynamically generated based on layout mode and I always get a height of 1024 back?

+ (CGRect)rectForView {
NSLog(@"The height is %f", [UIScreen mainScreen].bounds.size.height );
return CGRectMake( 0.0f, 0.0f, [[UIScreen mainScreen]bounds].size.width, (([UIScreen mainScreen].bounds.size.height ) - 100));
}

Answer

jdog picture jdog · Oct 10, 2012

Here is what I did to fix it.

+ (CGRect)rectForView {

if (UIInterfaceOrientationIsLandscape([[UIDevice currentDevice] orientation])) {

    return CGRectMake( 0.0f, 0.0f, [[UIScreen mainScreen]bounds].size.height, (([UIScreen mainScreen].bounds.size.width ) - 100));

}

NSLog(@"The height is %f", [UIScreen mainScreen].bounds.size.height );
return CGRectMake( 0.0f, 0.0f, [[UIScreen mainScreen]bounds].size.width, (([UIScreen mainScreen].bounds.size.height ) - 100));
}