Tom H
Tom H

Reputation: 1316

View's dimensions are reported switched around

So I put a:

NSLog(@"%f",self.superview.frame.size.height);

inside a UIView subclass of mine. When that code is run, it reports a height of 1024. However, the iPad is in landscape mode. When I run the same code (but with self.view.frame... instead) from the view controller, I get the expected result, a height of 748. I am certain that those are not the dimensions of the view because I set the background (of the superview) to red and it is certainly wider than tall.

What am I doing wrong?

any help is much appreciated, thank you

Upvotes: 0

Views: 83

Answers (2)

Philippe Sabourin
Philippe Sabourin

Reputation: 8075

You can easily get the correct rect not matter what by doing: [self.view convertRect:self.superview.frame fromView:nil];

It will convert it for the current state.

Upvotes: 1

Firoze Lafeer
Firoze Lafeer

Reputation: 17143

The origin and geometry of the iPad's screen remains the same, regardless of orientation. So in landscape mode, the "height" is still 1024, same as it would be in portrait mode.

Upvotes: 0

Related Questions