I'm using Swift 1.2
I'm trying to use this UIScrollview touchesbegan,touchesmoved,touchesended actions and the link in the 2nd comment of the accepted answer.
I'm using a storyboard with auto layout, I set my custom class for the UIScrollView in Custom Class.
I'm not receiving either of these touch events in the UIViewController that contains my custom UIScrollView
Edit: Updated my code for how I use it with @Victor Sigler 's answer.
Custom ScrollView Code:
import UIKit
protocol PassTouchesScrollViewDelegate {
func scrollTouchBegan(touches: Set<NSObject>, withEvent event: UIEvent)
func scrollTouchMoved(touches: Set<NSObject>, withEvent event: UIEvent)
}
class PassTouchesScrollView: UIScrollView {
var delegatePass : PassTouchesScrollViewDelegate?
override init(frame: CGRect) {
super.init(frame: frame)
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
self.delegatePass?.scrollTouchBegan(touches, withEvent: event)
}
override func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent) {
self.delegatePass?.scrollTouchMoved(touches, withEvent: event)
}
}
My ViewController:
import UIKit
class ViewController: UIViewController, PassTouchesScrollViewDelegate {
@IBOutlet weak var scrollView: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
scrollView.delegatePass = self
}
func scrollTouchBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
println("began \(touches)")
}
func scrollTouchMoved(touches: Set<NSObject>, withEvent event: UIEvent) {
println("moved \(touches)")
}
}
I'm trying to let a user draw a line over a UIImage, which I got working using a PanGesture Recognizer but the performance was very poor, especially on older hardware, I followed a Ray Wenderlich tutorial that used touches Began and the performance was much better, however it was on a UIView and not a ScrollView. I need a UIScrollView since prior to a user drawing on an image they can zoom in and around it.