15

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

0xSina
  • 20,973
  • 34
  • 136
  • 253
  • Have you tried allocating the `UIViewController` *before* pushing to it? – msgambel Nov 11 '13 at 23:31
  • @msgambel it is allocated before it's pushed. The inner expression is evaluated first, then outer. I haven't tried but I don't see how that makes a difference...it's the same thing. – 0xSina Nov 11 '13 at 23:36
  • @msgambel just tried, makes no difference... – 0xSina Nov 11 '13 at 23:37
  • Have you tried it in a real device ? – CoderPug Nov 11 '13 at 23:51
  • @0xSina No idea then. Maybe you're having memory allocation issues because too much is running? Have you tried turning on slow animations to see what's going on? – msgambel Nov 11 '13 at 23:54
  • @Coche no haven't tried on device yet. – 0xSina Nov 12 '13 at 00:15
  • +1 for the animated GIF. I had the exact same symptom. Setting an opaque background color fixed it for me too, but I really wish I knew why. – cduhn Apr 29 '16 at 18:48

3 Answers3

54

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).

Vincent Bernier
  • 8,674
  • 4
  • 35
  • 40
1

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.

Brian Green
  • 215
  • 3
  • 14
0

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.

Community
  • 1
  • 1
Barak Yoresh
  • 279
  • 2
  • 4