The application is slow due to UIImageViews

I have three large UIImageViews displaying images in my iPad application (each one has almost the size of the screen, and they have special effects like rotation, shadows , etc. to look like a news stack) When these Images are displayed, the application works VERY SLOW . UIAlertViews literally look like they only have two frames when they are presented, and the animation is not even laggy ... they are worse! But when I do not imagine UIImageViews, everything works quickly and elegantly. Obviously, I'm doing something wrong, as iOS can handle three images. Any suggestions on how to make the application faster? Thanks.

PS I don’t even want to know what happens when I double the image resolution for the new iPad haha

Change Here is the code that I use to set the shadows. This uses the QuartzCore structure.

page2.layer.shadowColor = [UIColor blackColor].CGColor; page2.layer.shadowOpacity = 1.0; page2.layer.shadowRadius = 10.0; page2.layer.shadowOffset = CGSizeMake(0, 4); 

Change 2 (Answer) . It seems that the lag is due to the way I adjust the shadows. If you set the shadowPath property to UIBezierPath the bounds of UIImageViews, rendering is faster and smoother, and the application speeds up significantly. Here is my final code:

 page2.layer.shadowColor = [UIColor blackColor].CGColor; page2.layer.shadowOpacity = 1.0; page2.layer.shadowRadius = 10.0; page2.layer.shadowOffset = CGSizeMake(0, 4); page2.layer.masksToBounds = NO; UIBezierPath *path2 = [UIBezierPath bezierPathWithRect:page2.bounds]; page2.layer.shadowPath = path2.CGPath; 
+3
source share
3 answers

We can only guess without seeing the actual code.

  • Shadows can be extremely expensive. Does it happen faster if you disable them or reduce shadowRadius ?
  • Setting the shadowPath property can lead to significant improvements if you can use it to get the effect you are looking for.
  • Otherwise: bake the shadows in your images or use another technique to fake the shadows around the edges of your images.
+3
source

If you use CALayer shadows, this can be a serious performance issue for any animations. They run a software renderer that is very harmful to the animation. If you have rectangular shadows, it’s best to draw a shadow, say Photoshop, and use it as an extensible image in separate views / layers. If your views have irregular shapes, you can draw them using Core Graphics, and it will still be much faster when animating.

+2
source

A better solution would be to make your shadows like images. However, I expect that performance using CALayer shadowRadius will be significantly improved if you manually set shadowPath .

Otherwise, it must be calculated by the system, each frame. Installing it on its own will lead to an offset animation.

+2
source

Source: https://habr.com/ru/post/911973/


All Articles