以编程方式对齐 iPhone 键盘顶部的工具栏 [英] Programmatically align a toolbar on top of the iPhone keyboard

查看:33
本文介绍了以编程方式对齐 iPhone 键盘顶部的工具栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某些情况下,我想在 iPhone 键盘的顶部添加一个工具栏(例如,当您在 iPhone Safari 中导航表单元素时).

In several cases I want to add a toolbar to the top of the iPhone keyboard (as in iPhone Safari when you're navigating form elements, for example).

目前我正在使用常量指定工具栏的矩形,但因为界面的其他元素在不断变化 - 屏幕顶部的工具栏和导航栏 - 每次我们对界面进行细微更改时,工具栏都会失去对齐.

Currently I am specifying the toolbar's rectangle with constants but because other elements of the interface are in flux - toolbars and nav bars at the top of the screen - every time we make a minor interface change, the toolbar goes out of alignment.

有没有办法以编程方式确定键盘相对于当前视图的位置?

Is there a way to programmatically determine the position of the keyboard in relation to the current view?

推荐答案

从 iOS 3.2 开始,有一种新方法可以实现这种效果:

As of iOS 3.2 there's a new way to achieve this effect:

UITextFieldsUITextViews 有一个 inputAccessoryView 属性,您可以将其设置为任何视图,该视图会自动显示在上方并使用键盘进行动画处理.

UITextFields and UITextViews have an inputAccessoryView property, which you can set to any view, that is automatically displayed above and animated with the keyboard.

请注意,您使用的视图不应位于其他地方的视图层次结构中,也不应将其添加到某个超级视图中,这是为您完成的.

Note that the view you use should neither be in the view hierarchy elsewhere, nor should you add it to some superview, this is done for you.

这篇关于以编程方式对齐 iPhone 键盘顶部的工具栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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