IOS: verify if a point is inside a rect

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

    Swift 4

    let view = ...
    let point = ...
    view.bounds.contains(point)
    

    Objective-C

    Use CGRectContainsPoint():

    bool CGRectContainsPoint(CGRect rect, CGPoint point);

    Parameters

    • 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.

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

提交回复
热议问题