如何将UIImage Dragging限制为其容器UIVIew的边界?

时间:2016-06-15 07:03:43

标签: swift uipangesturerecognizer

我正在与UIPanGesture合作。我能够拖动图像Hello World,但只是在背景图片的边界(这是一个UIView), 我不想让hello world图像的任何部分超出它所在的UIView。 我搜索了很多解决方案,但没有任何帮助。 请帮助我。

@IBAction func handlePan(recognizer:UIPanGestureRecognizer) {
     // customizable view is the UIView I want the image to stay in its bounds    

     let translation = recognizer.translationInView(self.customizableView)
    if let view = recognizer.view {

        view.center = CGPoint(x:view.center.x + translation.x,
                              y:view.center.y + translation.y)
    }

    recognizer.setTranslation(CGPointZero, inView: customizableView)
}

enter image description here

0 个答案:

没有答案