问题描述
在我的 iPad 应用程序中,我有三个显示图像的大型 UIImageView(每个都几乎是屏幕的大小,并且它们具有特殊效果,例如旋转、阴影 等,看起来像一个新闻堆栈).当显示这些图像时,应用程序会非常缓慢地运行.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,应用程序运行缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!