UIKeyboard Disabling Touch Events - ios

When the keyboard is displayed in my app, no touches will work in my view. I will tap a UITextField and the keyboard will be presented. Now that it is displayed, I cannot tap on other textfields,buttons or select text even in the active textfield.
Any ideas what may cause this
Thanks.
UPDATE 1:
I have found that because I animate the view upwards a little when the keyboard is displayed this is causing a problem. I have the master, view controller view. Inside this is formContainerView which contains my two UITextFields and UIButton.
I animate formContainerView up so that my fields aren't hidden behind the keyboard. I run the following code to do this:
[UIView animateWithDuration:duration delay:0 options:animationOptionsWithCurve(curve) animations:^{
[self.formContainerView setFrame:CGRectOffset(self.formContainerView.frame, 0, -220.0f)];
}
completion:^(BOOL finished) { }];
So I just offset the view by 220 pixels. If I set this to 0, i.e. don't animate the position, all touches work. But by moving the view up, all touches fail to work.
Why?

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
if ([txtfld_firstname isFirstResponder])
{
[txtfld_firstname resignFirstResponder];
[txtfld_secondname becomeFirstResponder];
}
return YES;
}
first set to the delegate for the textfield.
and after that write the above method when you click on the first textfield and after that press return button on the keyboard this (textfield delegate)method call and your keyboard disable.

Related

ios/objective-c: How to move view when button pressed

To move the view when a textfield is selected (bringing the textfield to the vertical center of the view), I am using textFieldDidBeginEditing and then when the user finishes, textFieldDidEndEditing to move the view back where it started.
This accomplishes the goal.
However, when it comes time for the user to press a submit button, a defect of the above is that the view shifts back before the VC disappears creating a jarring transition.
I would like the button to stay in the same place or at least have some control over the view in relation to the button.
Is there a way to exempt pressing the button from textFieldDidEndEditing or alternatively, is there a method similar to textFieldDidBeginEditing that applies to buttons so you can keep them in the center of the view.
This is what I am using for the textField
-(void)textFieldDidBeginEditing:(UITextField *)sender
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.3];
[UIView setAnimationBeginsFromCurrentState:TRUE];
if ([sender isEqual:_username]) {
self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y -70., self.view.frame.size.width, self.view.frame.size.height);
}
else if([sender isEqual:_password]) {
self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y -90., self.view.frame.size.width, self.view.frame.size.height);
}
else if([sender isEqual:_Email]) {
self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y -110., self.view.frame.size.width, self.view.frame.size.height);
}
Thanks for any suggestions.
You could set a flag in your view controller when the submit button is pressed and if the flag is set not do the scrolling animation on textFieldDidEndEditing.
Depending on the desired life cycle of the textfield delegate for the textfield, you can try setting the textfield delegate for that textfield to nil as the first line of code in method called when the submit button is pressed. If you do this then the textFieldDidEndEditing delegate method will not be called for that textfield and you will not have the jarring transition.

CGRectOffset animation misbehaved when working with TextField

The task is to move the textfield up when user done editing.
Right now, I have a text field textfield in the centre of the view, and a method moveTextFieldToTheTop.
Here is the code:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[_textField resignFirstResponder];
return NO;
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
[self moveTextFieldToTheTop];
}
- (void)moveTextFieldToTheTop
{
[UIView animateWithDuration:0.3
animations:^{
_textField.frame = CGRectOffset(_textField.frame, 0, -100);
}];
}
Instead of moving 100px up from the centre, textfield would somehow appear 100px below the centre and move to the centre position.
I debugged the code, and find out
[_textField resignFirstResponder];; is the cause of this problem.
But I really can't find out why and how to solve this problem.
Can someone please help me?
Update
I was using auto layout when I came across this problem. If I uncheck use auto layout, problem solved.
But is there a way to solve this problem with auto layout checked?
With auto layout change your moveTextFieldToTheTop method with this:
- (void)moveTextFieldToTheTop
{
//TODO update _textField's constraint to move _textField 100pt up
[_textField setNeedsLayout];
[UIView animateWithDuration:0.3
animations:^{
[_textField layoutIfNeeded];
}];
}
if you are using storyboard, then connect constraint of _textField to view controller, and update the code TODO part with that constraint(you need to change constraint .const property by 100)
Update
Here is the example project with textfield, just run the example, touch on textfield to open keyboard, and then press return button on keyboard.
https://www.dropbox.com/s/x138ta2uy1z3bbo/ToolBarhighlightproblem.zip?dl=0

iOS 8 - Keyboard Jumps when using Autocorrect

My view has two UITextFields. Let's call them TF1 and TF2. TF1 has autocorrectionType equal to UITextAutocorrectionTypeYes; TF2 has autocorrectionType equal to UITextAutocorrectionTypeNo. When going from TF1 to TF2, the transition is seamless. The predictive autocorrect toolbar disappears when going to TF2 and all is good.
The problem comes in when going from TF2 to TF1. When the autocorrect toolbar needs to be displayed, the whole keyboard will jump to the toolbar position then move itself down. It creates a jerky animation. What is causing this animation and how can I code for it? I would like these two textfields to have different autocorrection types, but still keep the transitions between them smooth.
I had a case something like your question in my app. What I did is just before entering the textview or textfield with UITextAutocorrectionTypeYes to disable the animations in UIView with [UIView setAnimationsEnabled:NO];
You can do something like this:
(BOOL)textViewShouldBeginEditing:(UITextView *)textView {
[UIView setAnimationsEnabled:NO];
return YES; }
(void)textViewDidBeginEditing:(UITextView *)textView {
[UIView setAnimationsEnabled:YES]; }
It not the most beautiful solution, but maybe it can help you to solve it:)

dismiss Keyboard not working

Hi, I am not able to dismiss keyboard. I have a scroll view which have UITextFields on a it. I tried using
[self.view endEditing:YES];
And
[self.scrollView endEditing:YES];
I tried using resignFirstResponder on individual textfields but no use.
This issue only occurs when I tap a textfield which I am using as button when taped upon it I use
[textField resignFirstResponder];
but old one don't resign whatever I do like I tried using endEditing before I resigned the button like textfield. So my question is what could be the problem in my scenario and is there any way to forcefully dismiss keyboard?
If you want textField to act as button, use delegates.
textField.delegate=self;
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
return NO;
}

Using next and previous button with UITextField, problems with firstresponder

I am using a subclass of a scrollview that moves the keyboard out of the way. (TPKeyboardAvoidingScrollView)
I think this is conflicting with my implementation of the next and previous buttons. I have built an inputaccessoryview
I have a category that sets the next and previous textfields for each field
when i edit a textfield, i set the current, previous and next textfields
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
_currentTextField = textField;
_prevTextField = [textField prevTextField];
_nextTextField = [textField nextTextField];
return YES;
}
when they click next or previous i call this method
- (void)selectAdjacentResponder:(id)sender{
UISegmentedControl *segmented = sender;
if(segmented.selectedSegmentIndex == 0){
[_prevTextField becomeFirstResponder];
} else {
[_nextTextField becomeFirstResponder];
}
}
this works fine.. but when i close the keyboard. my scrollview is messed up. if i add the line
[_currentTextField resignFirstResponder];
to the first line of my selectadjacent method it solves the problem. but the problem is it makes the screen focus in a funky way since i'm dismissing and accessing the next textfield at the same time.
i have tried resigning first responder when i close the keyboard. but i think my scrollview is calculated before that point.. any idea what to do =/

Resources