I think this has probably been asked, but after reading a lot, I’m not sure I have found an answer.
When the app is rotated to landscape, I’m adding a new view to the main view. The new view is constructed and added in code like this:
UIView * newView = ....
[rootView addSubview:newView];
But because the simulator is rotated to landscape when I add the new view I get this:
+------------------------------------------------------+
+ +---------------------------------------------+ +
+ | | | +
+ | | | +
+ | newView | rootView | +
+ | (Landscape | (Landscape) | +
+ | but portrait size) | | () +
+ | | | +
+ | | | +
+ | | | +
+ | | | +
+ +---------------------------------------------+ +
+------------------------------------------------------+
So I added newView.bounds = rootView.bounds; newView.center = rootView.center; thinking that would position the newView directly over the top of the rootView, but instead I got this:
+------------------------------------------------------+
+ +---------------------------------------------+ +
+ | | +
+ | | +
+ |--------------------------+ rootView | +
+ | | (Landscape) | +
+ | newView | | () +
+ | (Landscape size, | | +
+ | but offset) | | +
+ | | | +
+ | | | +
+ +---------------------------------------------+ +
+------------------------------------------------------+
I’m trying to figure out why they are different even though I’ve set the bounds and centers to be the same.
Dumping out the views I get this:
rootView; frame = (0 0; 768 1024); transform = [0, -1, 1, 0, 0, 0]; autoresize = W+H; layer = <CALayer: 0x98870a0>>
newView ; frame = (-128 128; 1024 768); autoresize = W+H; layer = <CALayer: 0x6e470a0>>
So it appears that the rootView is still 768w x 1024h, just rotated by a transform, and after setting bounds and centre, the new view is 1024w x 768h and offset by 128 points.
After some more playing around, I came up with this:
It works, I’m just wondering if there is a better solution.