在 iPhone & 上用 Quartz 绘制阴影很慢iPad.其他方式? [英] Drawing shadow with Quartz is slow on iPhone & iPad. Another way?

查看:32
本文介绍了在 iPhone & 上用 Quartz 绘制阴影很慢iPad.其他方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我发现在 iPhone/iPad 上为 UIView 添加阴影是多么容易时,我感到非常兴奋.

I was pretty excited when I found out just how easy it is to add shadows to my UIViews on the iPhone/iPad.

只需在Xcode中添加框架,在文件顶部添加导入:

Just add the framework in Xcode, add the import to the top of the file:

#import <QuartzCore/QuartzCore.h>

然后:

self.contentView.layer.shadowRadius = 3.0;
self.contentView.layer.shadowOffset = CGSizeMake(-2.0, -3.0);
self.contentView.layer.shadowOpacity = 0.5;
self.contentView.layer.shadowColor = [UIColor blackColor].CGColor;

虽然这确实在我的应用程序中创建了一个漂亮的阴影,但它现在在显示视图时也会让它死亡......即使在调试器之外启动也是如此.是否有什么我忘记了,或者这种方法对于更大的视图不实用?

While this does create a beautiful shadow in my app, it also lags it to death now when the view is shown... even when launched outside of the debugger. Is there something I'm forgetting or is this method just not practical for larger views?

作为参考,我在此处发布了屏幕截图.

For reference, I posted a screenshot here.

推荐答案

你应该设置shadowPath 属性.这就是 CoreGraphics 能够优化阴影的方式.

You should set the shadowPath property. It is how CoreGraphics is able to optimize shadows.

例如,如果您的视图是一个不透明的矩形:

For example, if your view is an opaque rectangle:

self.contentView.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.contentView.bounds].CGPath;

这篇关于在 iPhone &amp; 上用 Quartz 绘制阴影很慢iPad.其他方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆