How can I conditionally intercept touch events?

I am writing a custom keyboard extension for iOS 8 in Swift, and I am having trouble implementing Swype-style Swribble labels. Right now, my keyboard has a base UIView (the view property of my UIInputViewController ), which has a UIButtons number corresponding to the keys on the keyboard. Each of these keys responds to touchUpInside events and has UISwipeGestureRecognizers , which introduces secondary characters when scrolling up or down. I redefined touchesBegan:withEvent: to add a subcategory representation of the outlines and touchesEnded:withEvent: to remove the tab overlay in the UIInputViewController .

Currently, if I try to draw text starting from a certain distance between the buttons, the top view of the drawn labels is displayed correctly. However, if I start to write on top of the UIButton , the UIButton captures the touch event and does not forward it to my UIInputViewController .

How can I implement my keyboard in such a way that an overlay image with an inscription is displayed if the user sketches between the buttons, but otherwise presses the buttons / scroll buttons?

- EDIT -

I tried to resolve this by overriding the touchesBegan/Moved/Ended/Cancelled methods to forward the event to the next responder. If I click on the button and then on the other, I can get an inscription that appears between them. However, I still canโ€™t get anything to draw a button, like a doodle between the buttons. Anyone have a better idea?

- EDIT # 2 -

Currently, my view hierarchy is set up as follows: UIView (from UIInputViewController ) Subviews: all my buttons, and then my ScribbleView overlaying on subviews.

If I set userInteractionEnabled to true on my ScribbleView , I can get sketches to appear anywhere, regardless of the source location, but then I lose the functionality of the buttons.

As for the source code, I experimented with various configurations of passing touching events and something else, but the main code of the code can be found here: https://github.com/Kamaros/ELDeveloperKeyboard .

+6
source share
2 answers

I assume that I have not tried working with UIInputViewControllers yet. But what about subclassing UIButton and then overriding the touchesBegan:withEvent: and touchesEnded:withEvent: to redirect these events to your UIInputViewController?

0
source

I think you need to set your ScribbleView interationEnabled to YES and go to the button under the touch buttons you donโ€™t want. For example, if you recognize a long press in the same place or tap, then you know that the user wants to press a button.

0
source

Source: https://habr.com/ru/post/972556/


All Articles