UIButtons creating a native-like keyboard behavior - iphone

Greets. A somehow detailed explanation on my problem, and what I have already done, and what I cannot do.
I want to create a behavior resembling the one in the iPhone's keyboard. Basically, I want a view to appear when the user taps a button and WHILE the user taps that button.
This, I accomplished.
When the user lets go of the button WHILE his finger is on that button's area, I want to trigger an action "doing stuff".
This, I was also able to do.
Since all the buttons are near (like in the keyboard) and I don't want the user to select other button than the one he pressed, I reduced the hit area for the button using the -(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent )event function.
When the user presses the button, not lifting its finger, and dragging outside the button area, I want another action to trigger. This is the first problem... This function only triggers when the user's finger is far from the buttons' area, and this time the pointInside function is not being my friend. How can I detect the user finger "left" the button area the moment it exits its bounds?
This, in case you didn't realize... was problem 1.
The second problem is related with the drag enter. Again, I need to limit the area like in the drag exit. But I suppose that when I solve one of these, the other is the same. The problem is that in order to have a behavior like in the keyboard, I may need to detect the user started the touch in another button, never lifted his finger, and changed to another button. I can detect drag enter and drag exit IN THIS ORDER while on the same button. I cannot detect drag enter when the user first touched anywhere else other than the button where I want to detect the drag enter event. Basically what I need is to detect touch on any button (and not anywhere else in the view), and while the user is changing buttons without lifting the finger, I want to detect the new button being touched.
This gigantic paragraph was problem #2.
Any help, as you might guess, is highly appreciated.
Best Regards.
Thanks a lot!

Solved.
I used a custom UIButton class. Then, in
(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
I test if the touch occurred in that custom UIButton. And if it did, I act accordingly.

Related

touch events on UITextField rightView

I have several text fields which compromise a registration form . When the user hit submit and made invalid inputs the wrong fields are marked with an icon as rightView.
The rightView i use is a custom UIImageView subclass which has it's:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
overwritten to display a alert to tell the user what exactly is wrong with this field.
The problem is that the touchesBegan method is never called. Why is the view not receiving touch events when I touch it?
you need to enable user interaction of images to TRUE
[imageView setUserInteractionEnabled:YES];
You should check whether your view is on the upper level of views (that it's not overlayed by another transparrent view)
And also check for view's user interaction set to ENABLED
Also check that you tap directly on the view, this method is called only when you tap within your view's bounds
I also recommend you to read a bit about UITapGestureRecognizer class may be this would be more convenient way to use...

How can we detect touch up or click events in textview in IPhone

In IPhone?
Do we need a button control instead for that?
How can we pull that one up?
You can handle touch events directly in your view controller but this is usually a lot of effort. If you use a button with the type as custom it will look the same as a textview.
subclass UITextView and implement - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{}

Display tooltip on UITableView in iPhone

I was wondering if anyone has tried it. I need to show a tooltip within a table view when the user selects a word in the row's text.
Can you please help me or suggest any way for this?
Thanks in advance!!!!!!
In each cell add a UIView (be it a UITextView, UIImageView or whatever, in fact you can add plenty of additional subviews to it). Say you call it "tooltipView".
Now when user selects text, all you have to do is position (move around) that view near the selection (or where the user touched the row) and set the relative information. To track the selection, you can simply override the - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event method of your cell class and keep checking the point variable and corresponding event.

Tapping a UIScrollView to hide the keyboard?

(I posted this before anonymously, but then couldn't use the same computer again, so I'm posting it from my account now. Sorry to the guy who answered before.)
I'm working on an iPhone app which involves typing stuff into a UITextView, which adds content to a UITableView. The problem is, I need to be able to close the keyboard when the user's done with it, and the only area that is really visible other than the keyboard and UITextView at this point is the UITableView. I'm having trouble implementing a touch event on the UITableView (as in, touching the UITableView anywhere, not just didSelectRowAtIndexPath:). Here's the code I'm using in the view controller, but for some reason, it's not being executed at all:
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[textView resignFirstResponder];
}
Any suggestions?
"Here's the code I'm using in the view controller"
That's your problem - you have to create a subclass of UITableView and put the function in there before you will get those touch events.
Put an invisible button over the UITableView and trap the taps.
Yeah, I just said put a breakpoint in to make sure resignFirstResponder is actually being called and that it is being called on the correct text field.

iPhone custom keyboard

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