Junior — Middle
How can a gesture event handler be registered in an application?
sobes.tech AI
Answer from AI
In iOS, the UIGestureRecognizer class and its subclasses, such as UITapGestureRecognizer, UISwipeGestureRecognizer, and others, are used to register gesture handlers.
Example of registering a handler for recognizing a single tap:
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap))
view.addGestureRecognizer(tapGesture)
@objc func handleTap(_ sender: UITapGestureRecognizer) {
print("Touch gesture recognized")
}
Here, a gesture recognizer is created, added to the desired UIView, and when triggered, the handleTap method is called. This way, various gestures can be handled by registering the corresponding recognizers.