Reputation:
As the title reads, my problem is that my UILongPressGestureRecognizer sometimes does not run the code inside the sender.state = .ended
. The .began
always runs and works. I have tried to notice pattern but is to infrequent and I have not found a valid pattern or causation. I simply add my UITapGestureRecognizer UILongPressGestureRecognizer to my button:
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(normalTap(_:)))
tapGesture.numberOfTapsRequired = 1
camButton.addGestureRecognizer(tapGesture)
let longGesture = UILongPressGestureRecognizer(target: self, action: #selector(longTap(_:)))
longGesture.minimumPressDuration = 0.10
camButton.addGestureRecognizer(longGesture)
And then here is my longTap function:
@objc func longTap(_ sender: UIGestureRecognizer) {
if sender.state == .ended {
if movieOutput.recordedDuration.seconds == lastRecordDuration || movieOutput.recordedDuration.seconds <= 0.35 {
capturePhoto()
} else {
stopRecording()
}
} else if sender.state == .began {
startCapture()
}
}
I use the longPress for video and photos, and the TapGesture for photos only. Im using AVFoundation.
Upvotes: 2
Views: 796
Reputation: 207
I know this is old question, but writing for those who are facing issue like me.
You can get sender.state == .possible
when tap is ended.
Upvotes: 0
Reputation:
After receiving assistance from @rmaddy, the solution is basically to implement a .cancelled state action. For some reason the continuous gesture of UILongPressGesture got cancelled. In my code I implemented a `if sender.state == .cancelled.
Upvotes: 1