2011-04-22 85 views
4

我想知道是否有一个简单的方法来查明某个点是否在某个CGRect中?Cocoa-Touch:如何找出CGPoint是否在某个CGRect中?

我有这样获得的,其中用户触摸屏幕的位置:

UITouch *touch = [touches anyObject];  
CGPoint currentPosition = [touch locationInView:self.view]; 

不,我想看看这点在以下矩形:

CGRect aFrame = CGRectMake(0, 100, 320, 200); 

的下面显然不行:

if (currentPosition = aFrame) {//do something} 

我很感激任何帮助。非常感谢!

回答

11

使用CGRectContainsPoint功能,以确定是否点位于一个矩形内:

if (CGRectContainsPoint(aFrame, currentPosition)) 
    // Do something 
相关问题