0xSina
0xSina

Reputation: 21583

UINavigationController pushViewController pauses/freezes midway through

I am pushing a view controller via:

[self.navigationController pushViewController:[[UIViewController alloc] init] animated:YES];

But the animation lags/pauses a for half a second mid way through. The animation is not complete. Here's the gif;

enter image description here

Upvotes: 15

Views: 6042

Answers (3)

Brian Green
Brian Green

Reputation: 265

In app delegate, set your window's background color to white.

window?.backgroundColor = .white

Also in the the pushed view controller, set its view to white.

view.backgroundColor = .white

I experienced the same issue when programmatically embedding my view controller in a UINavigationController.

Upvotes: 1

Barak Yoresh
Barak Yoresh

Reputation: 299

While setting the background color as suggested by VinceBurn solved the pausing, it made the entire animation white, fading in the actual content only when the animation finished.

For me the problem was solved by making sure the content was correctly sized in -viewDidLoad.

Upvotes: 0

Vincent Bernier
Vincent Bernier

Reputation: 8664

With out more detail I can think of 2 possible problem with that.

  • Is there Shadow added in code to the view that will be covered by the new ViewController. If it is the case, use ShadowPath or an translucent view instead (the property Shadow is expensive while animating, been there done that)

  • Is the backgroundColor of new ViewController "clearColor" ? I've seen strange rendering problem with that kind of thing.

Try:

UIViewController *vc = [[UIViewController alloc] init];  
vc.view.backgroundColor = [UIColor whiteColor];  
[self.navigationController pushViewController:vc animated:YES];

That is the 2 possible problems I can think of the top of my head with so few detail.


Never rely on the default background color, it has change with iOS version and is not consistant across controls and can even be different if the view is created in code or from a Xib (in the same iOS version).

Upvotes: 54

Related Questions