Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pushviewcontroller animation is slow/choppy

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?

like image 652
user784625 Avatar asked Jan 12 '12 10:01

user784625


3 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;

}
like image 161
Joel Avatar answered Nov 12 '22 19:11

Joel


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.

like image 44
Indrajeet Avatar answered Nov 12 '22 19:11

Indrajeet


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.

like image 4
bandejapaisa Avatar answered Nov 12 '22 18:11

bandejapaisa