Curnelious
Curnelious

Reputation: 1

iPad2 only gives wrong width and height?

on any other device we use this code to set all views in landscape and everything fits great :

float width=[UIScreen mainScreen].bounds.size.width;
float height= [UIScreen mainScreen].bounds.size.height;

on the iPad 2 only , in order to make it work on landscape we have to swap the width and height, otherwise he puts views on portrait and they seems ugly.

Why is it happens only in iPad2 ?

Upvotes: 1

Views: 88

Answers (3)

tYp
tYp

Reputation: 121

It's not linked to the device but to iOS. Since iOS 8.0, the bounds is now dependent of the device orientation. I'm also swapping width and height like this :

CGRect ScreenBounds() { CGRect bounds = [UIScreen mainScreen].bounds; CGRect tmp_bounds = bounds; if(bounds.size.width < bounds.size.height) { bounds.size.width = tmp_bounds.size.height; bounds.size.height = tmp_bounds.size.width; } return bounds; }

Upvotes: 3

Amit Parpiyani
Amit Parpiyani

Reputation: 188

I had same issue From iOS 8 UIScreen is interface oriented so you will get proper results on devices which are running on iOS 8.

In order to support iOS 7 as well you can use following util method:

+ (CGSize)screenSize {
CGSize screenSize = [UIScreen mainScreen].bounds.size;
if ((NSFoundationVersionNumber <= NSFoundationVersionNumber_iOS_7_1) && UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
    return CGSizeMake(screenSize.height, screenSize.width);
}
return screenSize;
}

Upvotes: 1

Christian Schnorr
Christian Schnorr

Reputation: 10776

Don't size your views relative to the screen, but relative to their container view. Simple as that.

Upvotes: 2

Related Questions