I'm trying to get the time that a UIView
is pressed, using UILongPressGestureRecognizer
But, the states of press:UILongPressGestureRecognizer
are .began
, .end
, .cancelled
, .changed
.
But, I'm trying to know if has x
seconds pressed to change the control of the UIView
.
My current code is:
override func viewDidLoad() {
super.viewDidLoad()
let longPressRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(NavigationViewController.displayDebugger(_:)))
self.view.addGestureRecognizer(longPressRecognizer)
}
@objc public func displayDebugger(_ press:UILongPressGestureRecognizer){
if press.state == .began{
startDate = Date()
}
else if press.state == .ended{
endDate = Date()
let components = Calendar.current.dateComponents([.second], from: startDate, to: endDate)
if(components.second! >= 1){
let debugger = LogView()
debugger.loadRequests()
}
}
}
But, I don't find the way to know the pressed time. Exist a way to do it?