Reputation: 2135
I'm working with objective-c and I want to detect when the user is tapping a button (not when he tapped it, but the actual moment when is being taped until he stops). Is there any method? I'm not finding it if there's any. Thanks
Upvotes: 3
Views: 496
Reputation: 79636
Here (UIControlEvents) are all events of control/actions (with their brief description)
UIControlEventTouchCancel
: A system event canceling the current touches for the control.- UIControlEventTouchDown: A touch-down event in the control; when button is tapped/pressed.
UIControlEventTouchDownRepeat
: A repeated touch-down event in the control; for this event the value of the UITouch tapCount method is greater than one.UIControlEventTouchDragEnter
: An event where a finger is dragged into the bounds of the control.UIControlEventTouchDragExit
: An event where a finger is dragged from within a control to outside its bounds.UIControlEventTouchDragInside
: An event where a finger is dragged inside the bounds of the control.UIControlEventTouchDragOutside
: An event where a finger is dragged just outside the bounds of the control.UIControlEventTouchUpInside
: A touch-up event in the control where the finger is inside the bounds of the control.UIControlEventTouchUpOutside
: A touch-up event in the control where the finger is outside the bounds of the control.
Use Touch Down to get button tapping event.
Upvotes: 1
Reputation: 20804
Using touchDown
event you can make an action while your button is pressed
Example
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var label: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func testing(_ sender: Any) {
label.textColor = UIColor.red
}
@IBAction func testingCancel(_ sender: Any) {
label.textColor = UIColor.black
}
@IBAction func testingUpInside(_ sender: Any) {
label.textColor = UIColor.black
}
}
Upvotes: 3
Reputation: 16416
Yes it is possible
Button has following events to listen
You can use Touch Down
Upvotes: 0