I have 2 views, one login and another home. On clicking the signin button in my login view, on successful login, the user is redirected to the home view. Flip transition is implemented to acheive this. The problem is after the flip has occured, the home view layout is not displayed correctly. The view seems to drag itself above a little, leaving some white space at the bottom of the home view, i.e the home view contents do not fit correctly after the开发者_JS百科 flip. Here is the method which is called on successful login:
-(void)displayHome {
if (loginController == nil) {
[self loadhome];
}
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[homeController viewWillAppear:YES];
[loginController viewWillDisappear:YES];
[loginController.view removeFromSuperview];
[self.view addSubview:homeController.view];
[loginController viewDidDisappear:YES];
[homeController viewDidAppear:YES];
[UIView commitAnimations]; }
-(void)loadhome {
HomeController *hm = [[HomeController alloc]initWithNibName:@"Home" bundle:nil];
self.homeController = hm;
[hm release]; }
Any ideas on how to display the view contents correctly?
Thanks
I don't believe you need to manually call viewWillAppear etc. manually, I believe they are all called automatically. So they're probably being called twice which might cause a display/positioning error?
FWIW, an easier (and I'd argue better) approach is to display the login controller by calling presentModalViewController on homeController, especially if you are inheriting from UINavigationController. None of the Apple-provided nav-based apps do flipping AFAIK.
You should consider moving the viewDid{Appear/Disappear} calls into an animationDidStop delegate method as follows:
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:)];
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
[loginController viewDidDisappear:YES];
[homeController viewDidAppear:YES];
}
I doubt this will fix your problem (unless you are doing some layout in the viewDidAppear method?). But at least the viewDidAppear/viewDidDisappear methods of your View Controllers will be called at the correct time (when the animation is over, instead of when it has just started).
精彩评论