Replicating iOS Keyboard Functionality - ios

I have successfully added a custom keyboard (inputview), and it is fully functioning. I have ran into an issue that I can't seem to find an answer to.
My keyboard consists of a grid of buttons that is very much like UIKeyboardTypeDecimalPad, and each button adds or removes text from the UITextField when UIControlEventTouchUpInside is thrown just like one would expect.
My problem is that I want to be able to drag my finger around the keyboard, highlighting, but not actually selecting any key until the finger is raised (as one may normally do on an iPhone).
As it currently stands, the following happens:
- Touch down and highlight a key.
- Slide finger off key, key stays highlighted. (WRONG)
- Slide finger farther away, key becomes unhighlighted, doesn't select the adjacent key, and does not input text.
What can I do to fix this?

...when UIControlEventTouchUpInside is thrown just like one would
expect.
As one would expect, there's your problem. You need to listen and react to a combination of UIControlEventTouchDragInside and UIControlEventTouchDragOutside to replicate the iOS keyboard's highlighting pattern.

Related

Custom UIGestureRecognizer conflicting with UITapGestureRecognizer

So I have this project that I took from somebody else and they have implemented this OneFingerRotationGestureRecognizer (https://github.com/melle/OneFingerRotationGestureDemo/blob/master/OneFingerRotationGestureDemo/OneFingerRotationGestureRecognizer.m) for a circular slider. Additionally, they have added a UITapGestureRecognizer on top of that, so you could tap a value within that circular slider and the value would jump to that specific one. Now the problem is, when I drag that thing just a very small amount (imagine putting your thumb onto the control and tilting left/right), then the UITapGestureRecognizer also fires! And this is a problem, because I want to be able to grab the circular slider wherever I want (there is no handle or something). And when I only drag it a little, then the value just jumps to that spot where I did that small dragging. Somehow I need to cancel that tap gesture as soon as that OneFingerRotationGestureRecognizer started registering touches. I tried what is described here: https://developer.apple.com/documentation/uikit/touches_presses_and_gestures/coordinating_multiple_gesture_recognizers/preferring_one_gesture_over_another?language=objc but didn't have any success with that :-(.
What can I do? I'm afraid the solution is so simple that I just don't see it.

iOS Scrubbable Buttons

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.

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.)

IOS: Press and drag in button on custom keyboard

I'm building custom keyboard and i want to make response like stock keyboard.
- I can press and hold on one key and drag to other key and so release, the letter will be enter is the one at current finger position
- Can press and hold one key and use other finger to press on the other key and so 2 letters will be entered at the same time.
I've tried many methods in UIButton ( TouchUpInside, TouchDown, TouchUpOutside ... but didn't successed.
You are going beyond the abilities of UIButton. You need to look at creating a custom view which handles Multitouch Events.
It's not easy, but it's not impossible either.

Unable to implement UISlider for Accessibility option in iPad

i am trying to implement accessibility option in my book reader app. I have a slider(similar to ibooks) which is used for navigating between pages. i have seen this question posted by another user and implemented the same code in my app. Right now my slider is responding when i'm tapping on it. The voiceover is also speaking the label i have given in the code. But, the problem is that, i am unable to change the slider value and navigate to another page.. I dont know if it is the problem with my code or is it that i do not know how to replicate the gesture to change the value of the slider... Any help in this regard will be appreciated.... Thanku
Does the slider work with VoiceOver turned off?
If so, try swiping vertically up or down (top to bottom of display) after selecting the slider element with VoiceOver enabled.
Is it a UISlider, or something of your own devising? UISlider needs an actual vertical swipe once selected, and moves a pretty significant amount as a result — not a good experience for going to the next page.
If it's your own custom control, be sure you set UIAccessibilityTraitAdjustable.

Resources