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.
Related
Example 1:
When invoking 3D Touch on app icon, you are able to make selections without lifting the finger up.
Example 2
Long pressing on a keyboard key allowing you to drag in to different selections without lifting finger up.
If the app icon is the first view and the pop up is the second view, how can I transfer touch down from first to second view?
Normally, a view loses control of the touches when the fingers leave its area. But if you set isMultipleTouchEnabled to true, it will keep control over touches if the finger leave its area. If you use a button or another UIControl you can assign actions to touchDragExit, touchUpOutside or touchDragOutside etc. to handle events outside of the control.
So if any of you have used the tumblr mobile app recently, you'll notice that the reblog function has a tap and hold capability. Essentially when you tap and hold the reblog button, more buttons pop up around it so the user can just drag their finger over one of the new buttons and release to select it. I've been digging around and no one seems to have an answer to this specific question.I've always seen this as a very elegant way to have a sub menu and would like to implement it into my own apps. For ios btw.
Add gesture recognizer to a view. write a method to create buttons when long press gesture is done on the view.
I am thinking of developing a custom keyboard where each key has three distinct button actions:
Single tap
Double tap
Long press
1 and 2 are for directly inputting common characters while 3 will be for a pop menu to select input for less common characters.
I've used UIButton touchUpInside event for single tap and UITapGestureRecognizer for double tap. I can somewhat make it work as separate events on a single button in the Main Storyboard, but it was kind of wonky on the Keyboard Storyboard for the Keyboard View Controller. Double tap on the button doesn't do anything.
Any advice appreciated.
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.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Dismiss keyboard by touching background of UITableView
How do I make the keyboard go away when the user clicks somewhere else?
Note: I know how to make the keyboard disappear with sending the resignFirstResponder command to the UITextField. At present the "Done" button is connected to all the correct code to do this and this works.
I have a UITableView with different UITableViewCells, and if the user moves onto another cell I want the keyboard to disappear.
So what events do I also need to include the resignFirstResponder in, for the keyboard to disappear.
Suppose UITableViewCell A has the UITextField, and UITableViewCell B has a button. If the user presses the button in cell B, then I will need to send the command resignFirstResponder back to the UITextField in cell A. First of all the button has no idea which cell it should sent the command to, and second even if the button did know which cell to send the command to how would it?
There's no trivial way to do this. You can put a transparent set of "shield views" all the way around the text field that take up the rest of the screen, and use any touches on them to dismiss the keyboard.
You can create a generic 'hideKeyboard' method in which you can include all text fields that can be first responders. For example,
-(void) hideKeyboard {
[textFieldName resignFirstResponder];
[textFieldSurname resignFirstResponder];
for (UITextField * txtField in arrTextFields) {
[txtField resignFirstResponder];
}
}
Then, at various sections in your class, depending on the functionality required, call;
[self hideKeyBoard];
This simple method means you won't need to keep track of the individual item that 'has the focus' / first responder status.
How to touch any part of the screen to make the keyboard go away
To touch somewhere outside the UITableView and have the keyboard disappear, place an invisible button on top of the 'touch area' that you want to respond to. Then, simply call [self hideKeyboard] from the touch event for that invisible button. Using IB, drag a new rounded button onto your view, then size it to take up the full size of the screen. Next,drag the button up or down the controls list in the IB document window so that button is behind all text fields and buttons, but in front of anything else (like images etc.). Finally, change the type of the button to 'Custom' to make it invisible, but still respond to events. Now all you have to do is to connect the new button's 'touch up inside' event to trigger the 'hideKeyboard' method.
Additionally, see this post for a brilliant solution to dismiss the keyboard when the above solution doesn't work : stackoverflow question 1823317