• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

带有自定义视图的 inputAccessoryView 在我关闭键盘后隐藏

用户头像
it1352
帮助1

问题说明

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

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)

谢谢!

正确答案

#1

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

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

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhchafae
系列文章
更多 icon
同类精品
更多 icon
继续加载