设置GestureRecognizer的界限

时间:2017-09-18 17:34:07

标签: ios swift3

我正在尝试将限制设置为我的图像视图的边界,或者是为了防止图像/视图向外缩小或向左移动,因为它看起来非常糟糕。问题是Looks Good, Only should be able to zoom in ... Zoomed out, Looks Bad

@IBAction func scaleView(_ sender: UIPinchGestureRecognizer) {

    //print(self.my_new_fullimage)

    self.view.transform = self.view.transform.scaledBy(x: sender.scale, y:  sender.scale)
    sender.scale = 1

}
@IBAction func panView(_ gestureRecognizer: UIPanGestureRecognizer) {
    // Move the anchor point of the view's layer to the touch point
    // so that moving the view becomes simpler.
    let piece = gestureRecognizer.view
    //self.adjustAnchorPoint(gestureRecognizer: gestureRecognizer)

    if gestureRecognizer.state == .began || gestureRecognizer.state == .changed {
        // Get the distance moved since the last call to this method.
        let translation = gestureRecognizer.translation(in: piece?.superview)

        // Set the translation point to zero so that the translation distance
        // is only the change since the last call to this method. 
        piece?.center = CGPoint(x: ((piece?.center.x)! + translation.x), 
                                y: ((piece?.center.y)! + translation.y))
        gestureRecognizer.setTranslation(CGPoint.zero, in: piece?.superview)

    }
}

任何事都可以提供帮助。

-Thanks!

0 个答案:

没有答案