IOS: verify if a point is inside a rect

前端 未结 8 1418
夕颜
夕颜 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:33

    UIView's pointInside:withEvent: could be a good solution. Will return a boolean value indicating wether or not the given CGPoint is in the UIView instance you are using. Example:

    UIView *aView = [UIView alloc]initWithFrame:CGRectMake(0,0,100,100);
    CGPoint aPoint = CGPointMake(5,5);
    BOOL isPointInsideView = [aView pointInside:aPoint withEvent:nil];
    

提交回复
热议问题