Keyboard-like popup buttons, iOS
Imagine a normal keyboard (like English). When pressing and holding A for a while, a new menu with á, ä and other buttons popups up. And while still holding the first finger down on screen, you slide it on top of another of those buttons. As you slide it over a bu开发者_运维百科tton, it gets into highlighted mode (I assume), and when you slide out the highlighting is turned off. If you release the finger, the popup buttons disappear. If you held the finger over one of the buttons, that button's character is being typed into the text field...
I haven't found a way yet to pull this off. The long press thing isn't the problem. The problem is to allow sequential selection of the new buttons while still holding that first finger down - only one touch should be required to perform this.
The one touch allowing several selections is also existing in the passcode lock screen that pops up when going to Settings to change/edit current passcode settings. You can press and hold the 5, but if you slide that finger up to 2, 5 is deselected and 2 is selected and so on, without ever releasing the finger. (Also a UITextField with "Number pad" set has the same feature)
Anyone got an idea?
you need to use the touchesBegan: , touchesMoved: and touchesEnded: methods to detect when the finger is in contact and when it is lifted. Check the Apple documentation. You'll have to add the subview showing the extra characters on long press(which, as you say, you've already done) then use the touchesMoved to confirm that the finger is still in contact. Select the character on touchesEnded:
Seems like you could do it this way with IBAction
methods and gesture callbacks (only works on iOS 4.0 and later):
- on
UIControlEventTouchDown
: highlight current character - on triggering a
UILongPressGestureRecognizer
bound to each individual key: open menu for highlighted character directly above the current character (for bottom-positioned keyboards) or directly below the highlighted character (for top-positioned keyboards) - on triggering a
UITapGestureRecognizer
bound to each individual key: select highlighted character - on
UIControlEventTouchUpInside
on the multi-character menu: select highlighted character - on
UIControlEventTouchUpOutside
: cancel multi-character selection
One approach is to use tags for every button and a switch to determine which button was pressed, although it would kind of take a while to get all the buttons set up and everything... The Touches Began/Moved/Ended idea is pretty clever, but I'm not sure how you would accomplish that when using buttons. Perhaps use an image for every key and programmatically change the key images.
精彩评论