简体   繁体   English

如何创建一系列CGPoint(SWIFT)

[英]How to create a range of CGPoints (SWIFT)

I have a line in my view(as UIImage). 我的视线中有一行(如UIImage)。 I want something to happen when an area is touched. 我希望在触摸某个区域时发生一些事情。 How to create a range of CGPoints like with Integers? 如何使用Integers创建一系列CGPoint?

I want to do something like this: 我想做这样的事情:

var range = CGPoint(x:155.0...160.0,y: 132.0...136.0)

And then check whether the touched point is in that range. 然后检查触摸点是否在该范围内。

Sounds like what your really need is a GCRect . 听起来您真正需要的是GCRect

let rect = CGRect(x: 155, y: 132, width: 5, height: 4)

Then, to know if your touched point is inside this rect, just do: 然后,要知道您的接触点是否在此矩形内,只需执行以下操作:

rect.contains(touchedPoint)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM