带有自定义视图的 inputAccessoryView 在我关闭键盘后隐藏 [英] inputAccessoryView with custom view hide After I Dismiss keyboard

查看:74
本文介绍了带有自定义视图的 inputAccessoryView 在我关闭键盘后隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我的项目是如此结构化:

First of all , my project is so structured:

-带有tableView添加元素的主页

-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

现在,我有 inputAccessoryView 和关闭键盘的问题:

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

我使用 inputAccessoryView 在键盘上方移动自定义视图,如下所示:

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

MytextView.inputAccessoryView= MyContainerView; 

这可以正常工作.

当我使用以下方法关闭键盘时出现问题:

My problem occur when I dismiss keyboard using:

[MytextView resignFirstResponder];

键盘和相对 inputView 正确消失,但是当我再次尝试使 MytextView 时 firstResponder 不起作用(键盘未出现).

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

我猜测是因为textView被inputAccessoryView隐藏在屏幕下,inputAccessoryView改变了textview的初始位置(初始在屏幕中间);所以当我使用时 textView 不可聚焦并且键盘不出现:

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]

有没有办法以编程方式将 textView 重新定位到初始位置(屏幕中间),以便在我调用 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?

或者有没有办法在我关闭键盘时修复安全区域中的 inputAccessoryView?

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

(抱歉,我是 Objective-c 和 IOS 的新手)

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

谢谢!

推荐答案

让我跳出评论以获得更多自由.根据您的描述,您可以执行以下操作

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...
}

然后你可以重新定位或在那里做任何你需要的事情.或者,您也可以监听 UIKeyboardDidShowNotification 并在那里做准备工作.事实上,您可以通过这种方式使用一整套 UIKeyboard... 通知,希望对您有所帮助.

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.

编辑

如果您需要根据键盘大小重新定位,这里还有其他内容.

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 ...
}

这篇关于带有自定义视图的 inputAccessoryView 在我关闭键盘后隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆