在iPhone和iPhone上使用Quartz绘制阴影的速度很慢iPad兼容。其他方式? [英] Drawing shadow with Quartz is slow on iPhone & iPad. Another way?

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

问题描述

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

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和iPhone上使用Quartz绘制阴影的速度很慢iPad兼容。其他方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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