- 浏览: 110206 次
- 性别:
- 来自: 北京
最新评论
-
ocean1999:
有代码没 想学习哈 邮箱65614435@qq.com ,非常 ...
使用Google app做了个文件上传网站 http://avatar-share.appspot.com -
mywayscut:
很不错。详细介绍下吧,上传到blob的实现的怎么样的
使用Google app做了个文件上传网站 http://avatar-share.appspot.com
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 3425If you have ever written a ... -
实现键盘弹出后视图跟随键盘一起上下移动
2011-06-21 15:13 4948在.h中实现代码: @interface ShowTextf ... -
iPhone中使用NSLocalizedString实现国际化
2011-06-17 05:29 1635一、获取系统所支持的国际化信息在国际化之前,你可以在iph ... -
使用NSTimer与iphone的简单动画,实现飘雪效果
2011-06-17 05:27 1601使用NSTimer与iphone的简单动画,实现飘雪效 ... -
iOS常用的几个基础类 一个不用xib文件的例子
2011-04-14 13:23 8658我们从这张图开始说吧。从这张图我们可以很清楚的看到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 ...
世博小食游乐场安装通过npm: npm install react-native-keyboard-accessory --save 通过纱线: yarn add react-native-keyboard-accessory用法您可以使用KeyboardAccessoryView或KeyboardAccessoryNavigation组件...
《MFi Accessory Specification》这份文档详细阐述了苹果公司对于MFi配件的各项设计、制造和测试要求,是所有想要进入苹果生态系统的第三方配件制造商必须遵循的准则。以下我们将深入探讨这份规范中的关键知识点: ...
标题“android usb accessory”指的是Android设备作为USB附件的功能,它允许Android手机或平板电脑与外部硬件设备通过USB接口进行通信。这种功能使得Android设备能够作为Arduino等微控制器的主机,扩展其控制和交互...
USB Accessory USB从属demo是针对USB Human Interface Device (HID) accessory模式的一种示例应用。USB HID accessory模式主要用于非标准设备与Android设备之间的通信,例如游戏控制器、键盘、鼠标等。在这个demo中...
Accessory Interface Specification Release R32 2019-09-26
根据给定的文件信息,我们可以深入探讨Fuji Accessory Software的安装手册,这是一份详尽的指南,旨在帮助用户顺利地在各种环境下部署和配置该软件。以下是从标题、描述、标签以及部分内容中提取的关键知识点: ###...
本文档为《Accessory Interface Specification R29.pdf》(附件界面规范R29),是苹果公司发布的关于MFi(Made for iPhone/iPod/iPad)的开发文档。MFi程序旨在确保第三方配件与苹果设备(如iPhone、iPad和iPod)的...
AccessoryauthenticationprovidesamechanismforAppledevicestotrusttheidentitiesandfeaturesetsof accessoriesthatarecompliantwiththisspecification....
根据提供的文件信息,本文档是关于苹果公司的《Accessory Interface Specification 32》,这是一个适用于iOS开发者的技术规范,特别涉及到MFi认证和开发。本文档涉及Lightning接口的技术说明,以及与之相关的各种...
《Accessory Interface Specification 最新解密版》是针对苹果设备的配件接口规范文档,具有至关重要的参考价值。文档详细阐述了配件接口的规范内容、使用原则、测试指南、开发工具、适配器与代理以及各种兼容性问题...
- **辅助硬件(Miscellaneous/accessory hardware)**:例如网络交换机、路由器等,确保集群内部及与外部网络的有效连接。 - **整体硬件组装(Putting-it-all-together hardware)**:描述如何将各个组件合理地组合在...
根据给定文件的信息,我们可以详细地探讨一下在Windows Server 2003上使用Fuji Accessory Software时需要注意的关键知识点。 ### 使用Fuji Accessory Software的注意事项 #### 1.1 使用带有Internet Explorer增强...
《MFi Accessory Firmware Specification R45》是Apple公司针对其MFi(Made for iPhone/iPod/iPad)认证配件制定的固件规范文档。这份文档详细阐述了第三方开发者和制造商如何设计、开发和验证与Apple设备兼容的硬件...
《用于iOS的MFi认证资料:Accessory Interface Specification R31详解》 苹果的MFi(Made for iPhone/iPod/iPad)认证是针对第三方配件制造商的一项重要标准,旨在确保配件与苹果设备之间的兼容性和安全性。...
### Fuji Accessory Software 在 Windows Server 2003 上的安装与配置 #### 概述 本文档旨在为用户在Windows Server 2003环境下使用Fuji Accessory Software提供必要的指导。考虑到软件运行时可能会遇到的问题,...
标题《Accessory Interface Specification R22无水印,全书签》,描述《苹果配件开发,《Accessory Interface Specification R22》,内涵iap2开发协议》,以及标签“Apple accessory”表明这份文档是关于苹果配件...