IOS: verify if a point is inside a rect

前端 未结 8 1416
夕颜
夕颜 2021-01-30 04:55

Is there a way to verify if a CGPoint is inside a specific CGRect.

An example would be: I\'m dragging a UIImageView and I want t

8条回答
  •  醉话见心
    2021-01-30 05:13

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
                UITouch *touch = [[event allTouches] anyObject];
                CGPoint touchLocation = [touch locationInView:self.view];
                CGRect rect1 = CGRectMake(vwTable.frame.origin.x, 
                vwTable.frame.origin.y, vwTable.frame.size.width, 
                vwTable.frame.size.height);
                if (CGRectContainsPoint(rect1,touchLocation))
                NSLog(@"Inside");
                else
                NSLog(@"Outside");
        }
    

提交回复
热议问题