Questions with interactivePopGestureRecognizer when keyboard shown - objective-c

This is Screenshot
In View B, When keyboard is shown and pop viewController to View A with interactivePopGestureRecognizer, the keyboard is still stay here :(
How can let keyboard move with view B ?
(like iMessage or Facebook Messenger)
ps: I'm try to get keyboard view and add to self.view, it's useful, but i think it's not a good way.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardDidShown)
name:UIKeyboardDidShowNotification object:nil];
and
- (void)keyboardDidShown
{
UIView * keyboardView = self.textView.inputAccessoryView.superview;
[self.view addSubview: keyboardView];
}

Try this solution:
https://github.com/cotap/TAPKeyboardPop
This is lightweight category that listens interactivePopGestureRecognizer gesture and animating keyboard accordingly.

You don't add keybordView to the view. If you want to show keyboard for your UITextField/UITextView you call becomeFirstResponder on that object. In your example it should be:
[self.textView becomeFirstResponder];
If you want to hide keyboard you call:
[self.textView resignFirstResponder];
And if you want to hide your keyboard before you dismiss your ViewA you should call it in the beginning of your interactivePopGestureRecognizer when you start animation to show ViewB.
Hope it help.
//EXTENDED
I don't know why you are trying to add accessoryView as a subview to your view
- (void)keyboardDidShown
{
UIView * keyboardView = self.textView.inputAccessoryView.superview;
[self.view addSubview: keyboardView];
}
And I don't understand why do you use notification centre.
The functionality that the keyboard stay when you dismissed the view (as iMessage app) is a standard functionality.
Just use
[self.textView becomeFirstResponder];
when you want to show the keyboard and don't call
[self.textView resignFirstResponder];
when you pop your view controller. iOS does the job for you.

Related

Display modally custom keyboard view controller for editing a UITextField

By default when tapping on a UITextField iOS will display a default keyboard. Is it possible to bypass this? I would like to display modally a custom view controller on tap on the textField and be able to edit the textField through this controller.
Is there a recommended way?
Following wil repalce the keyboard as the input view when the user clicks on the UItextField.
self.TextField.inputView = "your view ";
Ok tried out the exact requirement you asked for:-
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
[textField resignFirstResponder];
POCModalViewController *objPOCModalViewController = [[POCModalViewController alloc]init];
[self presentViewController:objPOCModalViewController animated:YES completion:nil];
return NO;
}
Where POCModalViewController is the controller you want to present.
I would like to post the solution i have finally implemented, which is the closest to Footyapps27 solution:
I have made the controller that will present the modal controller(which will contain internally multiple custom keyboard views) as the uitextfield delegate for any UITextField objects contained within the view of my controller.
I can now received any notification through the - (BOOL)textFieldShouldBeginEditing:(TWValueInput *)textField method when a textfield start to be edited:
Within that delegate method I have the following code snippet:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
MyCustomKeyboardVC* vc = [[UIStoryboard storyboardWithName:#"main" bundle:nil] instantiateViewControllerWithIdentifier:#"customKeyboardController"];
vc.delegate = self;
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:vc animated:NO completion:nil];
return NO;
}
returning NO within that method will prevent the default keyboard from being displayed. There is no need actually to call the resignFirstResponderon the textfield.
I should point out though that the Apple recommended way to display a custom keyboard is to provide a custom view to the textfield inputView property like Divya mentioned. Since i wanted to managed multiple keyboard view entries it was quicker for me to display a custom keyboard controller through the delegate method i mentioned above.

iOS didSelectRow not called on selection a row?

I know its very basic question, but i'm facing a strange behaviour with UIPickerView.
Here is my scanario - I'm using UIPickerView in my app. my problem is that when i click on a row didSelectRow method is not called, however when i scroll rows of picker then its working.
more specific assume that first row on picker is currently selected and if i click on 4th row then didSelectRow method not fired.
What am i missing?
UPDATE: if i comment this code from viewDidLoad method then all works fine-
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:#selector(dismissKeyboard)];
[self.view addGestureRecognizer:tap];
and
-(void)dismissKeyboard {
[numberTextField resignFirstResponder];
[nameTextField resignFirstResponder];
[cityTextField resignFirstResponder];
[addressTextField resignFirstResponder];
[zipTextField resignFirstResponder];
}
I'm assuming you're trying to use the tap gesture recognizer to dismiss the keyboard if they click anywhere in the view. The problem this is causing is now your UIPicker is not getting touch events passed to it. I have two ideas for possible solutions.
1) Inside the method:
(CGPoint)locationOfTouch:(NSUInteger)touchIndex inView:(UIView *)view
test the location and/or the view to determine if the picker was touched or not, and then forward the event.
2) Instead of adding the tap recognizer to the entire view, add an invisible subview to the likely tap area to close the keyboard that won't overlap the picker.
Did you try adding Gesture recognizer to other parts of self.view than the pickerview?

Resize UIView and change subview position simultaneously

I have placed out a UIView with a UIButton as a subview in a ViewController in Interface Builder. I also have a UITextField where I have a action witch is triggered every time I type something in it. When I type something my view is supposed to get higher and the button should move to the bottom of the view. But when I type the first letter in the textfield the view resizes but the button doesn't move. When I type a second letter the button moves. Probably because the view is already resized. My question is how to get this to work simultaneously when typing the first letter in the textfield.
My code:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyPressed:) name:UITextFieldTextDidChangeNotification object:textField];
- (void)keyPressed:(NSNotification*)notification{
view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 200.0);
button.frame = CGRectMake(button.frame.origin.x, (view.frame.size.height-button.frame.size.height), button.frame.size.width, button.frame.size.height);
}
try to implement this method:
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
// put your action here
}
Solved it by putting the button at the bottom of the view. Then when I resized the view the button followed along by staying at the bottom. I didn't need to programmatically move the button.

How do I make the keyboard go away when a user clicks on the background of the view?

I have a UITextField in my iOS app. When a user enters text and clicks Return, the keyboard goes away due to a call to an IBAction with "resignFirstResponder."
However, XCode does not let me drag a line from the UIView itself to File Owner. How do I associate touching the background of a UIView with an IBAction that makes the keyboard go away?
You can use UITapGestureRecognizer. see: Dismiss keyboard by touching background of UITableView
so instead of tableview, just add it to your view instead:
UITapGestureRecognizer *gestureRecognizer = [[[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(hideKeyboard)] autorelease];
gestureRecognizer.cancelsTouchesInView = NO; //so that action such as clear text field button can be pressed
[self.view addGestureRecognizer:gestureRecognizer];
and have a method to hide your keyboard
- (void) hideKeyboard {
[self.view endEditing:YES];
}
You've already noticed that you can't drag from the UIView to the file's owner to assoctiate an action with a touch.
The way to work around this is to change the class of the background view from UIView to UIControl and hook up an action from there to a method in your controller to stop editing.
That's because a UIControl can respond to touch events, and a UIView does not, but a UIControl subclasses UIView, and so it can be used in place of a UIView.
I wrote an example project a while ago that uses this technique. Have a look at the secondViewController's xib file and see how I've change the class of the background view and hooked it up to a an action in the controller to dismiss the keyboard.
Use the touchesBegan with Event and end editing on the view:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self.view endEditing:YES];
}
One easy way to do it is to create a big transparent UIButton behind the view.

How to open an UIView in fullscreen mode with a tabbar?

this is my problem.
I have a tabBar application.
In first tab, i have a table.
On click on table it shows a modal
view.
To go back from modal view to first
view, i use
[self presentModalViewController:nw animated:YES];
The problem is that if i click on the tabbar while is opened a modal view, it opens second view, but first view's table don't work because the modal view is still opened althoug it appear as closed.
It's a way to open modal view in fullscreen covering the tab bar?
Or also to check if modal view is closed or not from another view?
EDIT:
I tried with all of this code:
nw = [[NewsViewController alloc] initWithNibName:#"NewsViewController" bundle:nil];
nw.modalInPopover = YES;
nw.wantsFullScreenLayout = YES;
nw.hidesBottomBarWhenPushed = YES;
nw.contentSizeForViewInPopover = CGSizeMake(320, 480);
nw.modalPresentationStyle = UIModalPresentationFullScreen;
nw.view.frame = [[UIScreen mainScreen] applicationFrame];
[nw.view setNeedsLayout];
but nothing!!! It wan't go in fullscreen!!
Any idea please?
thanks,
alberto
If the view you're presenting is full screen, this should obscure the tab bar. That said, you might need to re-size the view programmatically so that it's the same size as the UIWindow.
You should be able to do something along the lines of...
[nw setFrame:[[UIScreen mainScreen] applicationFrame]];
[nw setNeedsLayout];
...to achieve this. (Sorry, I'm on a Windows box at the moment, so I can't confirm this. Hopefully someone will provide any tweaks if required.)
You should then dismiss the initial modal view via a delegate method in the originating class. (See the "Dismissing a Modal View Controller" section of Apple's View Controller Programming Guide for iOS.) The originating class would then dispose of the modal view.
Resolved using notification!
When a tab change, i send a notification and close the modal controller.
- (BOOL)tabBarController:(UITabBarController *)tbController shouldSelectViewController:(UIViewController *)viewController {
[[NSNotificationCenter defaultCenter] postNotificationName:#"DataComplete" object:nil];
return YES;
}
In my view classes receive a notification and dismiss the controller!
- (void)downloadDataComplete:(NSNotification *)notif {
NSLog(#"Received Notification");
[self dismissModalViewControllerAnimated:YES];
}
Now it's possibile to reopen a modal view also changing tab!
This is a workaround but works!
alberto.