简体   繁体   中英

inputAccessoryView with custom view hide After I Dismiss keyboard

First of all, my project is so structured:

-home page with a tableView to add element

-floating Button: when clicked make appear keyboard with above a custom view (and inside a textView) to digit input

Now, I have a problem with inputAccessoryView and dismiss keyboard:

I have used inputAccessoryView to move a custom view above the keyboard like this:

MytextView.inputAccessoryView= MyContainerView; 

And this work correctly.

My problem occur when I dismiss keyboard using:

[MytextView resignFirstResponder];

The keyboard and relative inputView disappear properly but After when I try again to make MytextView the firstResponder does not work (the keyboard not appear).

I hypothesize that occurs because textView is hide with inputAccessoryView under the screen and inputAccessoryView change The inizial position of textview (Initial in the Middle of the screen); so textView is not focusable and keyboard not appear when I use:

[MyTextView becomeFirstResponder]

Is there a way to reposition programmatically the textView to initial position (middle of the screen) so can become focusable when I call becomeFirstResponder?

Or is there a way to fix inputAccessoryView in the safe area when i dismiss keyboard?

(Sorry, I'm New to objective-c and IOS)

Thanks!

Let me jump out of the comments to have more freedom. Based on your description you could do something like this

- (void) viewDidLoad
{
    super.viewDidLoad;
    [NSNotificationCenter.defaultCenter addObserver:self
                           selector:@selector( keyboardDidHide: )
                           name:UIKeyboardDidHideNotification
                         object:nil];
}

- ( void ) keyboardDidHide:( NSNotification * ) notification
{
... do stuff here...
}

Then you can reposition or do whatever you need in there. Alternatively, you can also listen for UIKeyboardDidShowNotification and do preparatory stuff there. In fact, there is a whole family of UIKeyboard... notifications that you could use this way and I hope it helps.

EDIT

Here is something else, if you ever need to reposition based on the keyboard size.

- ( void ) keyboardDidShow:(NSNotification *)notification
{
    NSDictionary * info = notification.userInfo;
    CGRect kbRect = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];

... do stuff with kbRect ...
}

have you tried to use

[self.view endEditing:YES]

to dismiss the input view?

I never get any issue to set any input to firstResponder after I trigger that code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM