Poor performance with basic animations and corner previews: how to improve?

I have 12 views that I rotate in much the same way as the home screen icons when you enter the desktop customization mode by touching the icon for a few seconds.

I am using 3D transform code to do the rotations. They have a duration of only 0.02 seconds, and the angle and direction of rotation are constantly changing during acceleration measurements.

5 of these views are fine, but 12 have very poor performance. Here's the rotation code:

CATransform3D rotatedTransform = CATransform3DRotate(CATransform3DIdentity, degrees * M_PI / 180.0, 0.0f, 0.0f, 1.0f);
self.layer.transform = rotatedTransform;

      

the main animation is wrapped around it. But I see a waste of cpu here as I don't make any 3D materials. I really only rotate 2D and nothing else. They are simple UIImageViews, but a custom class that does this rotation animation themselves.

I've heard that there are "affine" transformations that should work for 2D space. Would you advise changing it to 2D in this case?

Should I change the transformation of the layer or view? which is faster?

0


a source to share


4 answers


CALayer's rotations will be hardware accelerated, 2D and 3D transformations will be very similar, no redrawing occurs, no need to go to opengl, no need to cache.

Shark will help, but you will need to know what you are looking for and what you are looking for does not improve the performance of your current code, but removes your code entirely.

It looks like you are going through your own waaay code too often to change the angle of each layer. You win when you let the CA get the job done.



So, the strategy here is to find a way to get the CA to do the work and call it less than 50 times per second.

How about CAAnimationGroup

holding multiple CAPropertyAnimation

for each of your layers and setting up, say, one second of animation at a time?

Once you pass this to the CA, the CA will play it on its stream.

+1


a source


  • Shark. You need to know exactly what goes on slowly.

  • Try increasing the update interval from 0.02 to about 0.1 s; what is acceptable?

  • If all images are rotated together, use sublayerTransform

    on super layer instead of transforming each one separately

  • Try this without animation, just to make sure your callbacks work as you expect (setDisableActions: on CATransaction). Do you see the same things as the slow ones in the shark when you shoot them?

  • If you are doing this inside a scroll, you may have other problems. You need to take care of what's going on / off, etc.

  • 3D transforms have the same speed as affine ones in main animation AFAIK. sin / cos core material does not slow down the application.

More information about the actual effect you are trying to achieve will really help improve performance.



How big are the images on the screen?

+2


a source


My advice is to go OpenGL ES.


While Core Animation lags a little behind "UITransformations", the problem you are facing is classic: you are trying to create a framework with many "virtual" sprites floating around. This does not mean that UIKit is meant to be used . Especially the animations you are trying to do. Trigonometry is required to calculate pixel interpolation. This is a rather expensive procedure.

If there are clear limits on the intensity of the animation, the number of object animations at the same time, and the frequency of recalculation of new transformations, my only advice for you at the moment is OpenGL ES .

My experience with the iPhone so far has been pretty similar . Every time we squeezed an app, the current platform couldn't handle it. We ended up using OpenGL ES and it's well worth the learning curve. The performance is incredible .

I'm sorry about the "bad news", but I highly recommend using UIKit and Core Animation for frames for frame-based applications .

+1


a source


It looks like you are constantly redrawing your views. I'm sure there is a way to turn this off and only redraw at the end of the animation.

0


a source







All Articles