I want to have a button that triggers its method under the following conditions:
Basically, anytime any part of the button is touched, regardless of origin of touch, I want the method triggered, but want to accomplish this by manipulating UIButton properties, like touchedUpInside
and such.
Thanks for the suggestions!
Press the "Enter" key inside the input field to trigger the button: // Get the input field. var input = document.getElementById("myInput"); // Execute a function when the user releases a key on the keyboard.
Trigger a button click on keyboard "enter" with JavaScript. Press the "Enter" key inside the input field to trigger the button: // Get the input field. var input = document.getElementById("myInput"); // Execute a function when the user releases a key on the keyboard. input.addEventListener("keyup", function(event) {.
How To Make One Swift Button Action Process Method Handle Multiple Button On-Click Event. If there are multiple swift buttons in one iOS app, we can also use one method to process all those buttons’ on-click events. For example, if there are 3 buttons in the above example, btn1, btn2, and btn3.
The first method is to connect all the 3 buttons to the onClick swift button action process method follow section 2.1 Add Button onClick Event Handler Method. Then distinguish each button in the onClick method by the sender parameter.
Regarding:
- When the user presses the button and drags his/her finger out of the button's area
I recently have done something similar. Here is my code in Swift.
(In this example you subclassed UIButton, like: class FadingButton: UIButton
)
...
// The user tapped the button and then moved the finger around.
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesMoved(touches, with: event)
// Get the point to which the finger moved
if let point: CGPoint = touches.first?.location(in: self) {
// If the finger was dragged outside of the button...
if ((point.x < 0 || point.x > bounds.width) ||
(point.y < 0 || point.y > bounds.height)) {
// Do whatever you need here
}
}
}
...
I hope it helps someone.
Make you method such as -(IBAction)btnTap
and connect to these properties
Touch Down
method for thisTouch Up Inside
for this purposeTouch Drag Inside
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With