使UITextView成为其自己的inputAccessoryView [英] Make UITextView parent be its own inputAccessoryView

查看:99
本文介绍了使UITextView成为其自己的inputAccessoryView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现与Messages在iOS 7中相似的键盘交互.我有一个UIView,其中包含一个UITextView,并且当用户选择它以开始键入时,我想将此设置为 inputAccessoryView.这将为我处理动画,以及iOS 7中新的UIScrollView键盘关闭交互.

I'm trying to achieve a similar keyboard interaction that Messages has in iOS 7. I have a UIView which contains a UITextView, and when the user selects it to start typing, I want to make this UIView the inputAccessoryView. This would take care of the animation for me, as well as the new UIScrollView keyboard dismiss interaction in iOS 7.

UITextView开始编辑时,我正在尝试将其inputAccessoryView设置为其父级UIView(已在视图层次结构中).键盘出现,但没有附件视图.

When the UITextView begins editing, I'm trying to set its inputAccessoryView to its parent UIView (which is already in the view hierarchy). The keyboard appears but not with an accessory view.

我已经读到一些人正在使用UITextField的二重奏来完成这项工作,但这似乎是实现此目标的一种不好的方法.

I've read some people are using a duo of UITextFields to make this work, but that seems like a bad way to achieve this.

有什么建议吗?

推荐答案

一个简单得多的解决方案是使输入字段成为视图控制器的输入附件视图:

A much easier solution is to make your input field the input accessory view of your view controller:

- (BOOL)canBecomeFirstResponder
{
    return YES;
}

- (UIView *)inputAccessoryView
{
    return self.yourInputField;
}

该视图将显示在屏幕底部的屏幕上,当它成为响应用户点击它的第一响应者时,将显示键盘.该视图将被动画化,使其保留在键盘上方.

The view will be on screen at the bottom of the screen and when it becomes first responder in response to a user tapping it, the keyboard will be presented. The view will be animated such that it remains immediately above the keyboard.

这篇关于使UITextView成为其自己的inputAccessoryView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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