Cocoa-Touch:如何确定CGPoint是否在某个CGRect中?

n.e*_*ind 4 iphone cocoa-touch objective-c uitouch cgpoint

我想知道是否有一种简单的方法来确定某个CGRect中是否存在某个点?

我有这个来获取用户触摸屏幕的位置:

UITouch *touch = [touches anyObject];    
CGPoint currentPosition = [touch locationInView:self.view];
Run Code Online (Sandbox Code Playgroud)

不,我想知道这一点是否在以下矩形中:

CGRect aFrame = CGRectMake(0, 100, 320, 200);
Run Code Online (Sandbox Code Playgroud)

以下显然不起作用:

if (currentPosition = aFrame) {//do something}
Run Code Online (Sandbox Code Playgroud)

我会感激任何帮助.非常感谢!

Vla*_*mir 11

使用CGRectContainsPoint函数确定点是否位于矩形内:

if (CGRectContainsPoint(aFrame, currentPosition))
   // Do something
Run Code Online (Sandbox Code Playgroud)