How to limit pan gesture area?

后端 未结 4 1485
感情败类
感情败类 2021-01-03 05:18

I am having my UIImageView onto which I am having another UIView rectangle. By applying pan gesture to UIView rectangle it gets outsi

4条回答
  •  走了就别回头了
    2021-01-03 06:04

    Instead of manually computing whether the points are within the view's bounds, use CGRectContainsPoint(rect, point). This is what works for me, and I like it because it's shorter and more readable:

    func handlePan(pan: UIPanGestureRecognizer) {
        switch pan.state {
        case .Began:
            if CGRectContainsPoint(self.pannableView.frame, pan.locationInView(self.pannableView)) {
                // Gesture started inside the pannable view. Do your thing.
            }
    }
    

提交回复
热议问题