8

My view has the wrong dimensions. I am running a Landscape only but the view is reporting portrait dimensions "View Width = 768.000000 Height = 1024.000000" Any Ideas how to fix that? I have played around with the autorotate I have tried

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft|| interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

and

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

It looks fine on the view but have the dimensions are really messing with my app.

Jonathan
  • 507
  • 5
  • 15

1 Answers1

13

You should never use frame to tell your own dimension. frame is relative to the parent container view. To find the dimension with respect to your view's own coordinate system, use bounds: self.view.bounds

For example, the parent view may see the child view having width = 768 and height = 1024, but with a rotate 90 degree transform. This is how the parent view sees the child view, and this is what self.view.frame is about. The child view having a width = 1024 and height = 768 is reflected by how a view sees itself in its own coordinate system, which is self.view.bounds

nonopolarity
  • 146,324
  • 131
  • 460
  • 740
  • I tried using bounds but I still get the same results. I'm thinking that the view might not know that the iPad is in landscape. I don't know. – Jonathan Nov 17 '12 at 02:20
  • 1
    try printing out in `touchesBegan` and see if you see the same value? – nonopolarity Nov 17 '12 at 02:36
  • That worked, Thats super weird do you know why its was doing that? – Jonathan Nov 17 '12 at 02:50
  • 4
    of the earliest time you can see it correctly are `viewWillLayoutSubviews`, `viewDidLayoutSubviews`, `viewDidAppear`. For reference: http://stackoverflow.com/questions/12118920/on-an-ios-single-view-app-when-is-the-earliest-time-that-self-view-bounds-is-se – nonopolarity Nov 17 '12 at 03:56