- 浏览: 108535 次
- 性别:
- 来自: 北京
最新评论
-
ocean1999:
有代码没 想学习哈 邮箱65614435@qq.com ,非常 ...
使用Google app做了个文件上传网站 http://avatar-share.appspot.com -
mywayscut:
很不错。详细介绍下吧,上传到blob的实现的怎么样的
使用Google app做了个文件上传网站 http://avatar-share.appspot.com
Input Accessory View (How to add extra controls above keyboard)
- 博客分类:
- iOS開發
When building iPhone applications that support or provide text input, it’s often necessary to create some extra buttons (or other controls) beyond the ones provided by the default keyboard interface. Those buttons should be created for specific operations needed by your application, such as moving to the next or previous text field, make the keyboard disappear e.t.c. To understand what exactly this is all about, just see what’s happening when you are using the Safari browser and you type username/password values to login in your e-mail account. Just right above the keyboard, there are two buttons that allow you to move to the next or previous field and a third button that allows you to close the keyboard and see the whole browser again.
That area above the keyboard is an extra UIView, known as Input Accessory View. That view is supported by the UITextField and UITextView as well and is added to any control of that kind using thesetInputAccessoryView method. But that’s the last step. All the controls existsing in the Input Accessory View must be created prior to adding the view to the textfield/textview.
In this post I am going to show how to create an input accessory view programmatically. It’s supposed that you are already familiar writing code in the Xcode and have a basic knowledge on how to create UI controls and views manually. If you don’t, you’ ll learn now.
In this example we will create only two UITextFields. We will set the keyboard to numpad so we won’ t have any way at all to close the keyboard view. All those will be done using the Interface Builder. Then, programmatically we’ ll create two buttons to move between the fields and one more to close the keyboard view. We’ ll add these buttons to a UIView and set the view as our input accessory view that will appear every time that any of our two text fields get the focus (become first responder).
Let’s start. Create a new view-based application project named InputAccViewTest. Open the InputAccViewTestViewController.xib file using the interface builder and add two UITextFields at the top of your view (it should look like the following image):
After that select both of them and set the keyboard to numpad.
It's also necessary to connect every textfield's delegate to the File's Owner object if you want everything to work properly:
Now the real work. Go to the InputAccViewTestViewController.h file and declare the UITextFieldDelegate:
Your .h. file should look like this:
Don’t forget to release all of them in the dealloc method:
Go to the IB and connect the outlets to the UITextFields you created earlier.
Everything until here was more or less known stuff. Now create a method somewhere inside the .m file named createInputAccessoryView as below:
That method will create the buttons we need and prepare the inputAccView view.
Now implement the UITextField's delegate method textFieldDidBeginEditing. By using that method, we'll know when a textfield becomes first responder (gains the focus), so we can attach the input accessory view.
Note the txtActiveField. In that object is stored the selected UITextField every time it has the focus. That field will be used next and will help us to distinct which field is selected and how to move between them.
Inside the createInputAccessoryView method we used three methods: gotoPrevTextfield, gotoNextTextfield and doneTyping that they will trigger every event but they are not yet implemented. Go abovethe createInputAccessoryView method and copy or type the following three methods (the code inside them is quite straightforward and self-explanatory even though I've added some comments as well):
That's it. Build and run the app. Every time that we tap in a textfield three more buttons will show up along with the keyboard. Play with next, previous or done button. Below is an example on what you should see:
Please note that the buttons in this example are quite simple and of course in a real application you should take care of creating beautiful ones, using images or nice colors. That's up to your imagination. It would be a good idea to use background images for both normal and highlighted state for your buttons if you want to achieve the "animation" that simulates the finger tap.
That's all for the time being. There are more posts that will come (hopefully) soon. In any case, don't hesitate to experiment with everything that I mentioned in this post. I hope it will be useful.
Have a nice iPhone programming day.
发表评论
-
ios: 一个用户自定义键盘的例子
2011-10-23 03:15 3381If you have ever written a ... -
实现键盘弹出后视图跟随键盘一起上下移动
2011-06-21 15:13 4908在.h中实现代码: @interface ShowTextf ... -
iPhone中使用NSLocalizedString实现国际化
2011-06-17 05:29 1603一、获取系统所支持的国际化信息在国际化之前,你可以在iph ... -
使用NSTimer与iphone的简单动画,实现飘雪效果
2011-06-17 05:27 1567使用NSTimer与iphone的简单动画,实现飘雪效 ... -
iOS常用的几个基础类 一个不用xib文件的例子
2011-04-14 13:23 8621我们从这张图开始说吧。从这张图我们可以很清楚的看到iOS开 ...
相关推荐
This sample shows how to use a keyboard accessory view. The application uses a single view controller. The view controller's view is covered by a text view. When you tap the text view, the view ...
MFi Accessory Specification
Introduces Android Open Accessory and shows how to set up the hardware and development environment Explains how to code both Android and Arduino elements of an accessory Features four complete ...
316 pages ... How to get started with the Android accessory development kit How to create games with hardware or with Gameduino How to connect your Android phone to an Arduino sensor network
世博小食游乐场安装通过npm: npm install react-native-keyboard-accessory --save 通过纱线: yarn add react-native-keyboard-accessory用法您可以使用KeyboardAccessoryView或KeyboardAccessoryNavigation组件...
AccessoryauthenticationprovidesamechanismforAppledevicestotrusttheidentitiesandfeaturesetsof accessoriesthatarecompliantwiththisspecification....
Accessory Interface Specification Release R32 2019-09-26
android is usb accessory, ardunio is host.
Accessory Interface Specification 32 适合程序员 IOS工程师 永远MFI认证与开发,协议说明,lightning接口说明
主要是对usb hid的accessory从关系的demo研究
Accessory Interface Specification 最新版,已解密,可以直接复制,编写代码方便。版本R29.
Fuji Accessory Software Setup-JPN
Fuji Accessory Software Setup-ENG
Android Open Accessory is a new, simple, and secure protocol for connecting any microcontroller-empowered device to an Android smartphone or tablet. This Wrox guide shows Android programmers how to ...
99884959-Apple-Accessory-Protocol.pdf
MFi Accessory Firmware Specification R45
MFi Accessory Hardware Specification R9(20131008)
Accessory Interface Specification R27 lightning 接口协议
MFi Accessory Firmware Specification R40.pdf,开发ios硬件的必须文档
苹果设备配件设计指南Accessory Design Guidelines for Apple Devices