The view "jumps" when I add it to UIWindow as a subview (via the rootViewController property) and flip it

I have two simple UIViewControllers, their representations are 320 x 460 with status bars. I do in AppDelegate

self.window.rootViewController = [[[SimpleController alloc] init] autorelease]; [self.window makeKeyAndVisible]; 

In SimpleController, I have a button that makes

 - (IBAction) switchToVerySimpleController { [UIView transitionWithView: [[UIApplication sharedApplication] keyWindow] duration: 0.5 options: UIViewAnimationOptionTransitionFlipFromLeft animations:^{ [[UIApplication sharedApplication] keyWindow].rootViewController = [[[VerySimpleController alloc] init] autorelease]; } completion: NULL]; } 

The new view (VerySimpleController.view) is filled in blue. After the animation, the new view is shown with a tiny white stripe (with the size of the status bar) at the bottom, and then it rolls into place. Why is this happening and how to avoid it? I believe its status bar is to blame, and I tried setting statusBar = Unspecified to IB for both views, but that doesn't help.

UPDATE: When I hide the statusBar from the very beginning (via the setting in the .info file), the viewing setting does not happen. But still ... I need to show the statusBar, and I need this animation working properly.

+4
source share
2 answers

When a rootViewController is assigned to a window, a new frame is assigned in the rootViewController if a status bar is present. This is so that the rootViewController view will not be hidden under the status bar.

Since you set the rootViewController window inside the animation block, the new frame assignment is also animated.

In order not to show the transition, you can set the rootViewController view frame before the animation with something like this:

 - (IBAction) switchToVerySimpleController { CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame]; VerySimpleController *vsc = [[[VerySimpleController alloc] init] autorelease]; vsc.view.frame = CGRectMake(vsc.frame.origin.x, statusBarFrame.size.height, vsc.frame.size.width, vsc.frame.size.height); [UIView transitionWithView: [[UIApplication sharedApplication] keyWindow] duration: 0.5 options: UIViewAnimationOptionTransitionFlipFromLeft animations:^{ [[UIApplication sharedApplication] keyWindow].rootViewController = vsc } completion: NULL]; } 
+2
source

It seems that this question does sometimes happen, and this is probably a mistake.

To avoid this “jump”, add this code to the viewWillAppear method of the viewWillAppear controller that you want to show:

fast

 navigationController?.navigationBar.layer.removeAllAnimations() 

objective-c

 [self.navigationController.navigationBar.layer removeAllAnimations]; 

Now the transition will complete without a "jump".

0
source

All Articles