Tutorial :iPhone custom keyboard



Question:

I'm creating a custom keyboard with say 10 UIButtons laid out in a horizontal row. The buttons span the width of the screen, are the same size and must sit flush against each other.

I would also like to allow the user to choose a button by sliding a finger along the row of buttons. A preview of the chosen button is displayed elsewhere on the screen. The preview updates as the user moves their finger along the row. When the user is happy with their choice they release their finger, confirming the selection.

The obvious thing to try is UICountrolEventDragExit or UIControlEventDragOutside to remove the action of the previous button and UIControlEventTouchUpInside to activate the current button and kill previous touch events. However UICountrolEventDragExit and UIControlEventDragOutside are only activated when the user has dragged sufficiently far from the given button. Since my buttons must sit flush against each other this is too far and not good enough for me.

Suggestions?


Solution:1

Disable user interaction on the views used to display the buttons, and track all touches through the containing view. This is similar to how Apple's keyboard code works.

(alternatively, you could draw all of the buttons directly in the drawRect: of a single keyboard view, but that won't look proper during orientation changes)


Solution:2

If you want a 10 button 'keypad' I would look at using a UISegmentedControl. You can create one with 10 segments each with its own key and receive the key selected programatically like:

 segmentSelected = mySegmentControll.selectedSegmentIndex;  


Solution:3

Calling

-(void)touchesBegan:(NSSet )touches withEvent:(UIEvent)event;

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;

judiciously with a view showing 10 UIImages (not UIButtons) also works fine.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »