Junior — Middle
Can you explain what the UIGestureRecognizer class is and how it is used in iOS development?
sobes.tech AI
Answer from AI
UIGestureRecognizer is an abstract class in iOS used for recognizing user gestures such as taps, swipes, presses, etc.
It allows separating gesture handling logic from controller code, simplifying user input management.
Example of usage:
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap))
someView.addGestureRecognizer(tapGesture)
@objc func handleTap() {
print("View was tapped")
}
Here, a single tap recognizer is created, which calls the handleTap method when triggered.