I push a ViewController
which contains not too many views, UIScrollView
which contains 10 views inside, I have a singleton ViewController
and push it again and again without releasing and allocation again the ViewController
, so all the things I do it in viewDidLoad()
, and viewWillAppear()
, but the animation is slow and choppy, what it could be?

- 47,376
- 28
- 140
- 179

- 1,928
- 5
- 24
- 38
-
What device is this running on? – bandejapaisa Jan 12 '12 at 10:43
8 Answers
I had a problem where when UIViewController A did a pushViewController to push UIViewController B, the push animation would stop at about 25%, halt, and then slide B in the rest of the way.
This DID NOT happen on iOS 6, but as soon as I started using iOS 7 as the base SDK in XCode 5, this started happening.
The fix is that view controller B did not have a backgroundColor set on its root view (the root view is the one that is the value of viewController.view, that you typically set in loadView). Setting a backgroundColor in that root view's initializer fixed the problem.
I managed to fix this as follows:
// CASE 1: The root view for a UIViewController subclass that had a halting animation
- (id)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame])) {
// Do some initialization ...
// self.backgroundColor was NOT being set
// and animation in pushViewController was slow and stopped at 25% and paused
}
return self;
}
// CASE 2: HERE IS THE FIX
- (id)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame])) {
// Do some initialization ...
// Set self.backgroundColor for the fix!
// and animation in pushViewController is no longer slow and and no longer stopped at 25% and paused
self.backgroundColor = [UIColor whiteColor]; // or some other non-clear color
}
return self;
}

- 2,285
- 2
- 21
- 22
-
4Sure enough, setting the background color made everything smooth again. Thanks. – TPoschel Oct 31 '13 at 00:44
-
2Confirmed, this is the correct answer. For the record, you don't have to set the BG Color in the init method; you can just as easily put it in viewDidLoad. – DanM Jan 17 '14 at 19:38
-
That means, earlier, in the navigationController.view we set the background color, and in all the next views we draw with clearColor. So only once we'v to set bg color. Now its not possible, we'v to set in each view? – karim Mar 31 '14 at 08:05
-
1
-
1Yes! this is the answer, but what in the heck? Why does background color make it slow? – Jun 22 '14 at 04:51
-
2Had the same issue from Interface Builder. A default background caused the push animation to get temporarily frozen at about one third of the duration, then snap to the animation being finished. The background was also appeared black, so may have been clear. Setting a specific color fixed this and I wish I knew why. – William Robinson Mar 11 '15 at 17:17
-
adding a white background color works perfectly fine, still wondering why this has anything to do with setting a background color ? – Max Jul 13 '16 at 10:11
Only solution to this problem, never set background color of main view to clear color.
As your next view coming over the previous view, if you set background to clear color, means it is transparent, the previous view is always visible for sometime which spoil animation.

- 10,073
- 15
- 85
- 168

- 5,490
- 2
- 28
- 43
-
1Indeed. "The default value is nil, which results in a transparent background color." [Apple, https://developer.apple.com/reference/uikit/uiview/1622591-backgroundcolor ] – Donn Lee Mar 09 '17 at 02:15
-
1This question and answer is pretty hard to find ; adding keywords «previous UIViewController lingering during push» and «former view controller shown half-way with segue animation» – SwiftArchitect Jul 12 '17 at 18:16
You could start by using Instruments > Time Profiler and see if there is any part of your code that is taking longer than necessary.
You could also use the Instruments > Core Animation tool which can be used to flag parts of your screen that not drawing/animating efficiently.
If you're using an old iPhone or an original iPod - with complex screens, i've noticed some apps a bit choppy.

- 26,576
- 13
- 94
- 112
-
I'm using IPad 1 iOS 5, i checked the profile, I'm not noticing strange operations, everything seemed to be good, i have checked other apps which takes longer time and are so smooth, but this one is making me crazy. – user784625 Jan 12 '12 at 11:32
-
-
FPS is frames per second - basically the speed the animation is being rendered onto the screen. 60 is max on iPhone. 20 FPS is slow - then something is running inefficiently. – bandejapaisa Jan 13 '12 at 10:24
-
1You have already established you're running at 20 FPS, so you know something is taking too long. Run the Time Profiler - hide system libraries and see what pops up at the top of the list. Anything taking longer than main() or above 5% as a rule is probably inefficient and needs some attention. Instruments will point you to the line of code that is taking too long. It's hard to explain here - but you should read the instruments user guide: http://developer.apple.com/library/mac/#documentation/developertools/conceptual/InstrumentsUserGuide/Built-InInstruments/Built-InInstruments.html – bandejapaisa Jan 14 '12 at 17:05
I had this problem, and it was because of old code in the pushed view controller, which caused the view to "fade in", setting the alpha to 0 on viewWillAppear and setting the alpha to 1 on viewDidAppear.
I removed the old code that did this, and the push worked fine.
-(void)viewWillAppear {
self.view.alpha = 0; //REMOVE THIS LINE
}

- 7,789
- 1
- 24
- 17
My problem is I puts mass load codes in viewWillAppear
. My case is
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
tableView.reloadData()
}
And I have a lot of rows, so pushViewController is laggy.

- 601
- 1
- 11
- 15
This may be the known bug discussed in the linked an answer below. I had a similar issue and reading the answer below clarified it for me.
I've encountered the same issue today. I dug into the topic and it seems that it's related to the main runloop being asleep.
See this.

- 1
- 1

- 10,383
- 3
- 54
- 51
In my case I set ui change code ( such as shadow And cornerRadius And ...) in viewWillLayoutSubviews() method and when I put those code in other methods like viewWillAppear() that's transition get smoother

- 1,107
- 13
- 16
Swift: If you are applying shadow on any view etc then you can also try below code for this.
view.layer.shouldRasterize = true
view.layer.rasterizationScale = UIScreen.main.scale

- 3,049
- 1
- 34
- 45