I'm trying to create a programmable view controller with subviews that span the screen. I succeeded, and when I get to this view, the centered view appears in the center and rotates correctly when you rotate the device.
But in this navigation application, if I introduced a custom view when not in portrait mode, then the view that needs to be focused will position itself in a place that is not the center of the screen. I put all the necessary autoresize properties on the views, controller, parent, grandmother, holy virgin ... and I ran out of things to stick on the autoresist mask, and yet the example looks bad.
I am sure that I am missing a call to some magic method that will fix everything, but I did not understand how to call or where (setNeedsDisplay? SetNeedsLayout?). To demonstrate this problem, I created a complete example, available at https://github.com/gradha/iPhone-centered-rotation-test , which you can clone and run in a simulator or device. I created this from Apple's navigation controller by simply adding a fake cell that nudges the view I create manually.
The custom view can be found at https://github.com/gradha/iPhone-centered-rotation-test/blob/master/Classes/CenteredViewController.m , and here is the loadView method responsible for creating centered subzones:
self.view.backgroundColor = [UIColor yellowColor]; self.view.autoresizesSubviews = YES; self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; blue_ = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 130, 130)]; [self.view addSubview:blue_]; blue_.backgroundColor = [UIColor blueColor]; [blue_ release]; red_ = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)]; red_.backgroundColor = [UIColor redColor]; red_.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; red_.center = self.view.center; [self.view addSubview:red_]; [red_ release];
Here is a link to a step-by-step guide on the application screen , first entering portrait mode and screen rotation (OK), then input in landscape mode and rotation (depending on the side of rotation, it looks pretty bad). When you enter a view in landscape mode, depending on the orientation, the red square will have an upper left corner of 196x34 or 140x34, which is too different.
What am I missing to make these objects the focus of attention correctly when you enter a view in landscape mode and perform automatic rotation?