views:

139

answers:

2

In my iPhone app, I have a view controller with two views (essentially, a front & back view). The front view is the main UIView, and the back view is a secondary UIView which is added as a subview using [self.view addSubview:backView] when showing the back and [backView removeFromSuperview] when hiding it. However, when the orientation changes, I have the following issue: the main UIView (frontView) rotates & all of its elements resize properly, but the secondary/subview UIView (backView) does not rotate & all of its elements do not resize properly. Does anyone have suggestions on how to make the secondary UIView autoresize properly according to the rules I have set in Interface Builder?

A: 

If I understand correctly, at the time of rotation 'backView' has been removed from it's superview, yeah? If so, that's the cause of the problem. The autoresize property determines how the view resizes relative to it's superview. If it doesn't have a superview it won't resize.

Perhaps using [backView setHidden:YES] instead of [backView removeFromSuperview] will be sufficient for your needs.

imaginaryboy
Unfortunately, this happens even when backView is in the superview too. And I just tried out your suggestion to use `[backView setHidden:YES]` and it didn't do the trick either.
Jason
Is backView.autoresizesSubviews == YES? Presumably it would be since it's the default, but so far that's the only other thing I can think of.
imaginaryboy
Yes, it is equal to YES.
Jason
Is there a code sample you can post that actually exhibits the incorrect behavior?
imaginaryboy
A: 

In the end, the solution I found was simply to separate my UIViews into separate UIViewControllers, and make sure that any views that I wanted to be able to rotate only had one UIView.

Jason