在iPhone上从静止点到移动点画一条线
如何在一个点(一个 UIView 的中心)到一个移动点(触摸位置)之间绘制一条线,并且该线随着触摸移动而移动第二个点。
How can I draw a line between one point (the center of one UIView) to a point that moves (touch location), and the line moves the 2nd point as the touch moves.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在你的自定义视图中:
[self setNeedsDisplay]
以便视图重绘,drawRect:
中实现线条绘制,使用核心图形绘制一条线假设您将触摸点存储到属性
self.touchedPoint
中,那么绘制可能如下所示:In your custom view:
[self setNeedsDisplay]
so that the view would redrawdrawRect:
, use core graphics to draw a lineLet's say you store the touched point into property
self.touchedPoint
, then drawing might look like this:我对米哈尔的回答投了赞成票。但我还建议查看 Touches 示例项目。让它运行起来很容易 - 如果您仍在整理项目,这可能会有所帮助。
I voted Michal's answer up. But I would also suggest looking at the Touches sample project. It is easy to get it running - which may be helpful if you are still just putting together your project.