PDA

View Full Version : Replace UIView when rotating on the iPhone




cmorss
Jul 1, 2008, 09:15 PM
Hello,

I've been attempting to replace one UIView with another when rotating the iphone. I can replace the one view for another via the following code, but the views "walk" off the containing view and get resized smaller:

The two views I'm switching are the current view in the navigation controller and a card view. The card view is what is displayed when the in portrait mode. I put a containing view for both the navView and cardView to be placed in the hopes that I could have more control. All views have their own controllers and everything was wired up in IB (animation code has been removed just get it to work):

- (void)toggleCardAndDeckView {

UIView *navView = navigationController.view;
UIView *cardView = cardViewController.view;
UIView *baseView = baseViewController.view;

if ([navView superview] == nil) {
[cardView removeFromSuperview];
[baseView addSubview:navView];
}
else {
[navView removeFromSuperview];
[baseView addSubview:cardView];
}
}
The first time I rotate to the card view it looks okay. Moved down a bit but okay. When I then rotate back to the navView it gets allocated about 1/4 of the screen vertically. The next rotation is worse for both and finally they are no longer visible.

The rotation is triggered in the baseViewController (the container) via this:

- (void)willRotateToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation
duration: (NSTimeInterval)duration {
CardsAppDelegate *appDelegate = (CardsAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate toggleCardAndDeckView];
}

I tried it in the willRotateToInterfaceOrientation, willAnimateSecondHalfOfRotationFromInterfaceOrientation and didRotateFromInterfaceOrientation methods also with the same basic results.

My thoughts had been to set the new shown view's bounds to bounds of the container view, but the container view's bounds are always null!

I've seen this done before in videos so I know it works, but any help would be greatly appreciated.

Thanks,
Charlie



brian.v
Apr 29, 2009, 09:58 AM
Hey, how did you end up resolving this? I see lots of posts asking the same questions but no real answers.

Thanks in adavance.

cmorss
Apr 30, 2009, 10:37 AM
Hey, how did you end up resolving this? I see lots of posts asking the same questions but no real answers.


Wish I could help, but I'm sorry to say that I've never figured it out. I ended up moving on to other things.

Charlie