IOS:验证一个点是否在矩形内 [英] IOS: verify if a point is inside a rect

查看:828
本文介绍了IOS:验证一个点是否在矩形内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法验证 CGPoint 是否在特定 CGRect 中。
例如:我正在拖动 UIImageView ,我想验证它的中心点 CGPoint 是在另一个 UIImageView 里面我该怎么办?

Is there a way to verify if a CGPoint is inside a specific CGRect. At example: I'm dragging an UIImageView and I want to verify if its central point CGPoint is inside another UIImageView how can I do?

推荐答案

Swift



使用 CGRect.contains(_:CGPoint)

let rect = ...
let point = ...
rect.containsPoint(point)



目标-C



使用 CGRectContainsPoint()

bool CGRectContainsPoint(CGRect rect,CGPoint点);

参数


  • rect 要检查的矩形。

  • point 指向前胺。
    返回值
    如果矩形不为null或为空且该点位于矩形内,则为true;否则为false。否则,假。

  • rect The rectangle to examine.
  • point The point to examine. Return Value true if the rectangle is not null or empty and the point is located within the rectangle; otherwise, false.

如果一个点的坐标位于矩形内或最小X或最小Y边上,则该点被认为是在矩形内部。 。

A point is considered inside the rectangle if its coordinates lie inside the rectangle or on the minimum X or minimum Y edge.

这篇关于IOS:验证一个点是否在矩形内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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