本文介绍了由于UIImageViews,应用程序运行缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个大的UIImageViews在我的iPad应用程序中显示图像(每个都几乎是屏幕的大小,它们有特殊效果,如旋转,阴影等,看起来像新闻堆栈) 。显示这些图像后,应用程序将非常缓慢运行。 UIAlertViews看起来就像他们只有两帧时出现,而且动画甚至都没有延迟...它们更糟糕!但是当我没有呈现UIImageViews时,一切都能快速而优雅地运行。显然我正在做错事,因为iOS肯定可以处理三个图像。有关如何使应用程序运行更快的任何建议?谢谢。

I have three large UIImageViews displaying images within my iPad app (each is almost the size of the screen, and they have special effects such as rotation, shadows, etc to look like a news stack). When these images are displayed, the app runs VERY SLOWLY. UIAlertViews literally look like they have only two frames when they are presented and animations aren't even laggy... they're worse! But when I do not present the UIImageViews, everything works quickly and elegantly. Obviously I'm doing something incorrectly since iOS can surely handle three images. Any suggestions on how to make the app run more quickly? Thanks.

PS我甚至不想知道当我为新iPad加倍分辨率时会发生什么哈哈

PS I don't even want to know what will happen when I double the resolution of the images for the new iPad haha

编辑:这是我用来设置阴影的代码。这利用了QuartzCore框架。

Edit: Here is the code I am using to set the shadows. This utilizes the QuartzCore framework.

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

编辑2(答案):似乎滞后是因为我设置阴影的方式。 如果将shadowPath属性设置为UIImageViews边界的UIBezierPath,则渲染速度更快,更顺畅,并且应用程序显着加快。这是我的最终代码:

Edit 2 (Answer): It appears that the lag occurs because of the way I am setting the shadows. If you set the shadowPath property to be a UIBezierPath of the bounds of the UIImageViews, rendering occurs more quickly and smoothly and the app 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;


推荐答案

我们只能在不看实际代码的情况下猜测。

We can only guess without seeing the actual code.


  • 阴影可能非常昂贵。如果关闭它们,或者减少 shadowRadius ,它会变快吗?

  • 设置 shadowPath 属性可以带来巨大的改进,如果您可以使用它来获得您正在寻找的效果。

  • 否则:将阴影烘焙到图像中,或使用其他技术伪造图像边缘的阴影。

  • Shadows can be extremely expensive. Does it get faster if you turn them off, or decrease the shadowRadius?
  • Setting the shadowPath property can lead to a huge improvement, if you can use it to get the effect you're looking for.
  • Otherwise: bake the shadows into your images, or use some other technique to fake the shadows around the edges of your images.

这篇关于由于UIImageViews,应用程序运行缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 08:54