iOS Scrubbable Buttons - ios

On the keyboard and in the native calculator app on iOS, it's possible to put your finger down on one button, like '0', and then move your finger to the another button, like '1', release your finger, and have it enter '1'. On the calculator it darkens the button under your finger.
If you start pressing a button, drag your finger outside of the buttons, and then move it back in, it'll continue to highlight the buttons under your finger. However, if you don't start on a button—like you start dragging from the calculator results label—and drag onto the buttons, the buttons do not highlight.
What's the best approach to mimic the calculator's behaviour for buttons? I'm mostly looking for code structuring guidance rather than code examples here!
It seems I won't be encapsulate each button in its own view class, but I'll have to have a Keyboard that handles all the touches, and manually draws the buttons.

I think the easiest way is to add handling for touch control events:
UIControlEventTouchDragInside
UIControlEventTouchDragOutside
UIControlEventTouchDragEnter
And link all the components with some kind of processing logic. Initial control event location and so on.

Related

React Native press and hold, drag finger to another touchable and capture touch by that view

In my React Native app I'm trying to have a button that the user can long press, and without lifting their finger, able to interact with another view. Here is roughly what I want:
Think of it like how 3D touch/long press worked prior to iOS 13/14 (depending on place in system and device): user either 3D touched or long pressed a button, for example an app icon, and a contextual menu popped up. Then, users could, without lifting the finger, hover onto one of the buttons and release their finger, triggering the button tap.
I have complete control over my buttons, touchables, and views (even the tab bar is custom, as opposed to the illustrations I made above).
How can I achieve this? (I'm on React Native 0.63)
There may be a better solution to this but off the top of my head I would use the Gesture Responder System
https://reactnative.dev/docs/gesture-responder-system
You can have a one container view that wraps tab bar and buttons. Then listen to the onResponderMove event to decide when these buttons should appear. This may happen for example when the locationY exceeds some value.
You can also use the onResponderRelease event (again with the help of locationX and locationY parameters) to determine if the finger was released above the button.

UIView: Inheriting Touch

Example 1:
When invoking 3D Touch on app icon, you are able to make selections without lifting the finger up.
Example 2
Long pressing on a keyboard key allowing you to drag in to different selections without lifting finger up.
If the app icon is the first view and the pop up is the second view, how can I transfer touch down from first to second view?
Normally, a view loses control of the touches when the fingers leave its area. But if you set isMultipleTouchEnabled to true, it will keep control over touches if the finger leave its area. If you use a button or another UIControl you can assign actions to touchDragExit, touchUpOutside or touchDragOutside etc. to handle events outside of the control.

How Do I Trigger a Button By Sliding Onto It?

I'm working on an app with a musical keyboard component.
I need 2 types of "sent events" to trigger the keys of the keyboard (UIButtons).
1) "Touch Down" triggers the buttons they way I need it to
2) The 2nd way I need buttons to be triggered is by sliding onto a button,from another button/key to the side of it as if it is "touched down" upon, when it is slid upon from the left or right.
How do I achieve this?
You can't do this using the built-in control events of the buttons, for the simple reason that you don't get an event in a button at all unless the touch is initially in that button (as I explain here: https://stackoverflow.com/a/40414929/341994).
Still, this doesn't sound very hard to do. The simplest approach is probably to put the touch response (such as a gesture recognizer) into the common superview of all the buttons. The superview can then track the gesture. And it can very easily find out which button the touch is currently inside at any given moment. So it can manage the whole interaction. It can even send messages to the buttons telling them when to highlight and unhighlight. (And if you aren't going to use the button touch handling for anything, you might even want to give up the idea that these are buttons; they could just be views or custom controls that look like buttons.)

Fire and cancel touch events manually

I have a question about programming my own third-party keyboard for iOS8. My keyboard already looks pretty good, but some functionalities are missing. If you look at the standard keyboard on an iPhone you can press any button and if you swipe your finger to another button, the touch event of the first button gets cancelled and your second button is "active". So e.g. if I press the button "E" and swipe my finger to "R" and release my finger, the letter "R" is the selected one. But I don't know how to implement this.
Now in my app when I press a button and swipe my finger around, this button never gets "released". Seems like I'm stuck on that button as long is I have my finger put on the display.
I think I need these touch events:
TouchUpInside: when the user taps a button, and releases it inside the buttons' frame, this event gets fired (that's when I want to write a letter)
TouchDragInside: That's the event when I already have my finger on the display and swipe my finger "inside" the buttons' frame.
TouchDragOutside: Same as above, just swiping outside the buttons' frame.
But here's the problem: TouchDragInside just get's fired for the button I tap. So when TouchDragOutside gets fired, I have to "release" the button and make the button active where my finger is at the moment.
I hope you understand my question, if you need some further information or some details just let me know.
You could consider not using UIControl at all.
Just use a transparent overlay on top of all the keys so that you can manually deal with which key the message should be dispatched towards.

custom button requirements for the ipad - what is the best approach?

I'm trying to build a set of buttons that behave slightly different than regular buttons. The requirements are:
When a user's finger slides over a button, it should highlight (a custom image changes).
When a user's finger slides off the button, it reverts the highlight.
When a user's finger slides off the button and onto a new button (without lifting the finger), a new button highlights and the old one reverts.
If a user's finger is released while on top of the button, the button triggers and the highlight stays.
I think I can implement 1, 2 and 4 using existing the existing button framework.
However, 3 is not possible. As the system continues to register touches when I drag off the button and does not register touches on the new button unless I release. Any ideas?

Resources