1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Replace UIView when rotating on the iPhone

Discussion in 'iPhone/iPad Programming' started by cmorss, Jul 1, 2008.

  1. macrumors newbie


    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.

  2. macrumors newbie

    Hey, how did you end up resolving this? I see lots of posts asking the same questions but no real answers.

    Thanks in adavance.
  3. macrumors newbie


    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.


Share This Page