Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

cmorss

macrumors newbie
Original poster
Jul 1, 2008
2
0
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):
Code:
- (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:
Code:
- (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

macrumors newbie
Apr 29, 2009
1
0
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

macrumors newbie
Original poster
Jul 1, 2008
2
0
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.