我似乎无法以编程方式工作。我有一个UIImageView,我想制作Draggable和Pinchable。 可拖动部分的所有内容都在工作,另一方面捏合似乎不起作用。
My Custom UIImageView Class子类 UIImageView 和Implements UIGestureRecognizerDelegate
在我的初始化函数中,我有以下内容:
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.initializeGestures()
}
override init(image: UIImage?) {
super.init(image: image)
self.initializeGestures()
}
func initializeGestures() {
self.userInteractionEnabled = true
self.multipleTouchEnabled = true
dragGesture = UIPanGestureRecognizer(target: self, action: "handlePan:")
zoomGesture = UIPinchGestureRecognizer(target: self, action: "handlePinch:")
self.addGestureRecognizer(dragGesture)
self.addGestureRecognizer(zoomGesture)
}
接下来是以下几行代码:
func handlePan(recognizer: UIPanGestureRecognizer!) {
Scripts.log("PAN >>> DRAG ACTIVATED")
}
func handlePinch(recognizer: UIPinchGestureRecognizer) {
Scripts.log("PINCH >>> ZOOM ACTIVATED")
recognizer.view?.transform = CGAffineTransformScale((recognizer.view?.transform)!, recognizer.scale, recognizer.scale)
recognizer.scale = 1
}
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}