Every gesture has the following states:
.Began
.Changed
.Ended
.Possible
.Cancelled
.Failed
You’ll mostly be using the top 3, and when you do this is how you do it:
obj.addLongPressGestureRecognizer { locations, center, state {
switch state {
case .Began:
//do stuff
case .Changed:
// do stuff
case .Ended:
// do stuff
}
}
By default, a long press gesture takes 0.25s
to trigger. That means the user needs to hold down for that long before the .Began
state triggers. However, you can easily change that time like this:
press.minimumPressDuration = 0.0
let c = Circle(center: canvas.center, radius: canvas.height/3)
c.lineWidth = 40.0
let press = c.addLongPressGestureRecognizer { locations, center, state in
switch state {
case .Began, .Changed:
c.fillColor = Color(red: random01(), green: random01(), blue: random01(), alpha: 1.0)
c.strokeColor = Color(red: random01(), green: random01(), blue: random01(), alpha: 1.0)
default:
c.fillColor = C4Blue
c.strokeColor = C4Purple
}
}
press.minimumPressDuration = 0.0
canvas.add(c)