歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> iPhone開發--鍵盤上加懸浮框(toolbar)

iPhone開發--鍵盤上加懸浮框(toolbar)

日期:2017/3/1 10:18:24   编辑:Linux編程

之前做了個小功能,就是發微博時顯示剩余的字數,我的傻傻的思路是直接算鍵盤的高度,並在鍵盤上面的位置貼個laber,哈哈,後來我現任的leader說這麼做很fool(鍵盤中文高度和英文高度是不同的,你還得算?),iPhone的鍵盤有個屬性,可以直接設置在鍵盤上的toolbar。我於是乎找啊找,終於在stackoverflow上找到了答案。哈。分享下:

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

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.

大意是(我大言不慚的意譯下):
iOS3.2以後增加了一個實現此功能的方法:

UITextFields和UITextView有一個inputAccessoryView的屬性,當你想在鍵盤上增加個view時,你就可以講該屬性的值設為該view。之後在鍵盤的上方就會自動的顯示你設的view了。

注意你使用的view不要繼承自別的地方,不要把它添加到別的超類上(翻譯的怪怪的,童鞋們還是看原版的吧)。

Copyright © Linux教程網 All Rights Reserved