0

I'm facing an issue which is caused by orientation magic I don't understand. First, I'm using a NavigationController which loads a ViewController. In this ViewController is a ScrollView. When I ask for the position of the ScrollView, I get wrong data. For example: The x coordinate of the ScrollView is 90 in the interface builder. If I get the frame of the ScrollView programmatically it returns 280. Everything in the App is set to landscape. In the Info.plist, in the summary, in the implementation of the ViewControllers, in the interface builder.

I made some screenshots. Maybe are they helping finding the mistake.

Settings in the summary

Frame in the interface builder of the ScrollView

Frame in the implementation where bar is different from the interface builder

The settings of the ViewController who contain the ScrollView

And every ViewController has this:

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

If I remove the NavigationController from the Storyboard and leave the simulated metrics to inferred, then the first ViewController swaps to portrait in the Storyboard.

When I log the size of the view from the NavigationController is it in portrait

NSLog(@"frame %@", NSStringFromCGRect(self.view.frame));

The output is 768x1024

zeiteisen
  • 7,078
  • 5
  • 50
  • 68

2 Answers2

1

I thought you usually had to take orientation into account when you calculated x off of a frame, which is why they have transforms? iPhone SDK: Orientation (Landscape and Portrait views)

Simply querying the frame for an X value wont always give you accurate results.

Community
  • 1
  • 1
ddoor
  • 5,819
  • 9
  • 34
  • 41
0

The problem is the method used ie the viewDidLoad: method. At that time no subviews are yet drawn and no frames are initialized yet, so the problem is accord.

Instead of using the viewDidLoad: use viewWillAppear:animated: or viewDidAppear:animated: will solve the problem for you.

Happy Coding :)

The iOSDev
  • 5,237
  • 7
  • 41
  • 78