7

I'm working on an iPad project, currently it's on Landscape view. And I tried doing:

self.view.frame.size.height

Why is this always returning 960? While as in landscape the height dimension of the view itself should be 768 right?

What I am trying to do is to allocInitWithFrame a UIToolbar that is located at the bottom. The UIToolBar has a height of 50, so here's what I did which failed:

self.bottom_bar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.frame.size.height-50, self.view.frame.size.width, 50)];

Why is this and how do I do this?

Irfan
  • 4,301
  • 6
  • 29
  • 46
adit
  • 32,574
  • 72
  • 229
  • 373

1 Answers1

6

Two postings (one and two) referenced a similar problem. They both suggest using self.view.bounds instead of self.view.frame.size.width because the bounds change along with the interface orientation.

Community
  • 1
  • 1
Carter
  • 3,053
  • 1
  • 17
  • 22
  • 1
    I tried chaing it to self.bottom_bar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height-50, self.view.bounds.size.width, 50)]; and it's the same thing – adit Jul 21 '11 at 03:52
  • Looking around some more, it looks like [this link](http://stackoverflow.com/questions/5194504/reporting-incorrect-bounds-in-landscape-mode) had the same problem. I think they solved it by implementing didRotateFromInterfaceOrientation after the view had loaded and getting the view.bounds there. – Carter Jul 21 '11 at 04:49
  • had this problem too. Self.view.bounds works great for me. Cheers – pnizzle Sep 11 '12 at 04:30