I can't seem to get this to work programatically. I have a UIImageView which I want to make Draggable and Pinchable. Everything for the draggable part is working, the pinch on the other hand doesn't seem to work.
My Custom UIImageView Class subclasses UIImageView and Implements UIGestureRecognizerDelegate
In my init functions I have the following:
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)
}
Followed by the following lines of code:
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
}