iOS输入法开发(Swift)
![](http://www.cocoachina.com/cms/uploads/allimg/140827/4196_140827101845_1.png)
- class UIInputViewController : UIViewController, UITextInputDelegate, NSObjectProtocol {
- var inputView: UIInputView!
- var textDocumentProxy: NSObject! { get }
- func dismissKeyboard()
- func advanceToNextInputMode()
- // This will not provide a complete repository of a language's vocabulary.
- // It is solely intended to supplement existing lexicons.
- func requestSupplementaryLexiconWithCompletion(completionHandler: ((UILexicon!) -> Void)!)
- }
![](http://www.cocoachina.com/cms/uploads/allimg/140827/4196_140827101949_1.png)
![](http://www.cocoachina.com/cms/uploads/allimg/140827/4196_140827102024_1.png)
![](http://www.cocoachina.com/cms/uploads/allimg/140827/4196_140827102047_1.png)
- func addNextKeyboardButton() {
- self.nextKeyboardButton = UIButton.buttonWithType(.System) as UIButton
- ...
- var nextKeyboardButtonBottomConstraint = NSLayoutConstraint(item: self.nextKeyboardButton, attribute: .Bottom, relatedBy: .Equal, toItem: self.view, attribute: .Bottom, multiplier: 1.0, constant: -10.0)
- self.view.addConstraints([nextKeyboardButtonLeftSideConstraint, nextKeyboardButtonBottomConstraint])
- }
- class KeyboardViewController: UIInputViewController {
- ...
- override func viewDidLoad() {
- super.viewDidLoad()
- addKeyboardButtons()
- }
- func addKeyboardButtons() {
- addNextKeyboardButton()
- }
- ...
- }
- class KeyboardViewController: UIInputViewController {
- var nextKeyboardButton: UIButton!
- var dotButton: UIButton!
- ...
- }
- func addDot() {
- // initialize the button
- dotButton = UIButton.buttonWithType(.System) as UIButton
- dotButton.setTitle(".", forState: .Normal)
- dotButton.sizeToFit()
- dotButton.setTranslatesAutoresizingMaskIntoConstraints(false)
- // adding a callback
- dotButton.addTarget(self, action: "didTapDot", forControlEvents: .TouchUpInside)
- // make the font bigger
- dotButton.titleLabel.font = UIFont.systemFontOfSize(32)
- // add rounded corners
- dotButton.backgroundColor = UIColor(white: 0.9, alpha: 1)
- dotButton.layer.cornerRadius = 5
- view.addSubview(dotButton)
- // makes the vertical centers equa;
- var dotCenterYConstraint = NSLayoutConstraint(item: dotButton, attribute: .CenterY, relatedBy: .Equal, toItem: view, attribute: .CenterY, multiplier: 1.0, constant: 0)
- // set the button 50 points to the left (-) of the horizontal center
- var dotCenterXConstraint = NSLayoutConstraint(item: dotButton, attribute: .CenterX, relatedBy: .Equal, toItem: view, attribute: .CenterX, multiplier: 1.0, constant: -50)
- view.addConstraints([dotCenterXConstraint, dotCenterYConstraint])
- }
- func addDash() {
- ...
- // set the button 50 points to the left (-) of the horizontal center
- var dotCenterXConstraint = NSLayoutConstraint(item: dotButton, attribute: .CenterX, relatedBy: .Equal, toItem: view, attribute: .CenterX, multiplier: 1.0, constant: -50)
- view.addConstraints([dashCenterXConstraint, dashCenterYConstraint])
- func addDelete() {
- deleteButton = UIButton.buttonWithType(.System) as UIButton
- deleteButton.setTitle(" Delete ", forState: .Normal)
- deleteButton.sizeToFit()
- deleteButton.setTranslatesAutoresizingMaskIntoConstraints(false)
- deleteButton.addTarget(self, action: "didTapDelete", forControlEvents: .TouchUpInside)
- deleteButton.backgroundColor = UIColor(white: 0.9, alpha: 1)
- deleteButton.layer.cornerRadius = 5
- view.addSubview(deleteButton)
- var rightSideConstraint = NSLayoutConstraint(item: deleteButton, attribute: .Right, relatedBy: .Equal, toItem: view, attribute: .Right, multiplier: 1.0, constant: -10.0)
- var topConstraint = NSLayoutConstraint(item: deleteButton, attribute: .Top, relatedBy: .Equal, toItem: view, attribute: .Top, multiplier: 1.0, constant: +10.0)
- view.addConstraints([rightSideConstraint, topConstraint])
- func addHideKeyboardButton() {
- hideKeyboardButton = UIButton.buttonWithType(.System) as UIButton
- hideKeyboardButton.setTitle("Hide Keyboard", forState: .Normal)
- hideKeyboardButton.sizeToFit()
- hideKeyboardButton.setTranslatesAutoresizingMaskIntoConstraints(false)
- hideKeyboardButton.addTarget(self, action: "dismissKeyboard", forControlEvents: .TouchUpInside)
- view.addSubview(hideKeyboardButton)
- var rightSideConstraint = NSLayoutConstraint(item: hideKeyboardButton, attribute: .Right, relatedBy: .Equal, toItem: view, attribute: .Right, multiplier: 1.0, constant: -10.0)
- var bottomConstraint = NSLayoutConstraint(item: hideKeyboardButton, attribute: .Bottom, relatedBy: .Equal, toItem: view, attribute: .Bottom, multiplier: 1.0, constant: -10.0)
- view.addConstraints([rightSideConstraint, bottomConstraint])
- }
![](http://www.cocoachina.com/cms/uploads/allimg/140827/4196_140827102450_1.png)
![](http://www.cocoachina.com/cms/uploads/allimg/140827/4196_140827102503_1.png)
![](http://www.cocoachina.com/cms/uploads/allimg/140827/4196_140827102517_1.png)
![](http://www.cocoachina.com/cms/uploads/allimg/140827/4196_140827102530_1.png)
- class KeyboardViewController: UIInputViewController {
- ...
- var customInterface: UIView!
- init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
- super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
- var nib = UINib(nibName: "CustomKeyBoardInterface", bundle: nil)
- let objects = nib.instantiateWithOwner(self, options: nil)
- customInterface = objects[0] as UIView
- }
- ...
- }
- class KeyboardViewController: UIInputViewController {
- ...
- override func viewDidLoad() {
- super.viewDidLoad()
- view.addSubview(customInterface)
- ...
- }
- ...
- }
- class KeyboardViewController: UIInputViewController {
- ...
- @IBAction func didTapWeheartSwift() {
- var proxy = textDocumentProxy as UITextDocumentProxy
- proxy.insertText("We ? Swift")
- }
- ...
- }
![](http://www.cocoachina.com/cms/uploads/allimg/140827/4196_140827102741_1.png)
![](http://www.cocoachina.com/cms/uploads/allimg/140827/4196_140827102802_1.png)
![](http://www.cocoachina.com/cms/uploads/allimg/140827/4196_140827102818_1.png)
![](http://www.cocoachina.com/cms/uploads/allimg/140827/4196_140827102933_1.png)
![](http://www.cocoachina.com/cms/uploads/allimg/140827/4196_140827102841_1.png)
iOS输入法开发(Swift)相关推荐
- android输入法框架分析,Android与iOS输入法开发框架比较谈
对于任何一个使用手机的人,有一样工具是不可能缺少的,它既不是微信之类的社交工具,也不是支付宝之类的金融工具(事实上这两个都越界了),而是输入法这样的输入工具.更重要的是,输入法还是一种特权工具,因为它 ...
- ios 输入法扩展_搜狗输入法 iOS 版开发与优化实践
输入法是一种对性能要求极高的产品,不同于普通应用开发,很多在普通应用开发看来不是问题的,在输入法看来却是比较关键.同时,由于 iOS 系统的某些限制,输入法不得不在产品功能和性能方面做出调整,以尽可能 ...
- 专访搜狗输入法 iOS 版开发负责人李腾杰:第三方输入法开发与优化实践
输入法是一种对性能要求极高的产品,不同于普通应用开发,很多在普通应用开发看来不是问题的,在输入法看来却是比较关键.同时,由于 iOS 系统的某些限制,输入法不得不在产品功能和性能方面做出调整,以尽可能 ...
- iOS开发Swift篇—(六)流程控制
iOS开发Swift篇-(六)流程控制 一.swift中的流程控制 Swift支持的流程结构如下: 循环结构:for.for-in.while.do-while 选择结构:if.switch 注意:这 ...
- 李洪强iOS开发Swift篇—02_变量和常量
李洪强iOS开发Swift篇-02_变量和常量 一.语言的性能 (1)根据WWDC的展示 在进行复杂对象排序时Objective-C的性能是Python的2.8倍,Swift的性能是Python的3. ...
- pythonios脚本语言-iOS开发Swift篇—(一)简单介绍
一.简介 Swift是苹果于2014年WWDC(苹果开发者大会)发布的全新编程语言 Swift在天朝译为"雨燕",是它的LOGO 是一只燕子,跟Objective-C一样,可以用于 ...
- iOS 跨平台开发,该用 Flutter 还是 Swift?
[CSDN 编者按]在商业和开源代码中被广泛使用的 Flutter 和 Swift 你更中意哪一个呢?本文对两者的优势.性能.流行度等方面进行比较分析,帮助您找出更适合自己项目的框架或语言. 作者 | ...
- iOS开发 swift 3dTouch实现 附代码
iOS开发 swift 3dTouch实现 附代码 一.What? 从iphone6s开始,苹果手机加入了3d touch技术,最简单的理解就是可以读取用户的点击屏幕力度大小,根据力度大小给予不同的反 ...
- 了解Swift:15个适合iOS应用开发的初学者友好资源
现在是开始在iOS上使用Swift编程语言进行编程的好时机. 但是从哪里开始呢? 尽管有很多很棒的Swift和iOS程序员免费资源,但是并不是所有的资源都是为初学者设计的. 从Apple自己出色的指南 ...
最新文章
- 其实win10要比win7的安全性强很多
- 基于 RocketMQ Prometheus Exporter 打造定制化 DevOps 平台
- 组合数据类型练习,英文词频统计实例9-21
- 剪裁tiff影像数据_能看更会用,超擎影像云平台带你轻松玩转海量影像!
- 总结获取原生JS(javascript)的父节点、子节点、兄弟节点
- C++ primer 第7章 类
- java arraylist底层实现原理_ArrayList和LinkedList底层原理
- vs怎么更改编译的堆空间_再见吧 buildSrc, 拥抱 Composing builds 提升 Android 编译速度...
- 090525 T 站点地图接口
- 从决策树学习谈到贝叶斯分类算法、EM、HMM - 结构之法 算法之道
- 加速你的vs.net开发环境
- 大数据超详细面试题汇总(附答案)
- Qt练习项目--鼠标连点器
- 算法——最短路径应用
- Centos7 ,使用grep,cut 、awk 提取IP地址
- 国内外无代码可视化开发平台一览
- Guitar Pro8苹果mac最新版本下载安装教程
- python 线性回归显著性检验_回归方程及回归系数的显著性检验_stata显著性检验...
- 小度电视伴侣与小米电视音响对比评测
- 10Mbps是多少网速呢