让触摸在 UIView 子类中留下发光的痕迹
在 UIView 子类中,让触摸留下短暂后消失的发光痕迹的最佳方法是什么?
这里的“最好”主要是指最简单、最高效。我正在使用 touchesBegan 等拦截触摸事件。我希望了解如何使用 Core Graphics 或其他策略来实现此目的的一些具体细节。褪色可能是这里的关键。
编辑:我有在drawRect
方法中以各种方式使用Core Graphics基于触摸绘制路径的经验。我很好奇实现淡入淡出机制的特定方法不会产生巨大的性能成本。
In a UIView subclass, what's the best way to have touches leave glowing trails that fade after a short time?
'Best' here mainly means simplest and most efficient. I'm intercepting touch events with touchesBegan
etc. I would love some specific details of how to use Core Graphics or other strategies to accomplish this. The fading is probably the key here.
EDIT: I have experience drawing paths based on touches using Core Graphics in various ways in the drawRect
method. I'm curious about particular ways of implementing the fading mechanism that will not have a huge performance cost.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会调查
CAEmitterLayer
。它经过高度优化,但仅在 iOS 5 上可用。要创建辉光轨迹,请考虑调整发射器的lifetime
属性。要使用发射器来实现您的目标,我只想说您应该在
-touchesMoved: withEvent:
中实现某种跟踪,以随用户的位置移动粒子发射器。I'd look into
CAEmitterLayer
. It's highly-optimized, but it's only available on iOS 5. To create the glow trail, look into tweaking thelifetime
property of the emitter.To use the emitter to accomplish your goal, I'd just say you should implement some sort of tracking in your
-touchesMoved: withEvent:
that moves particle emitter along with the user's location.