三、为各特殊按键加上应有的功能
1、还记得我们一开始创建的 didTapButton Function么?我们只需要在该段代码中加入 switch 判断语句、对按下之按键的值进行判断并执行相应的动作:
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21  | 
						    func didTapButton(sender: AnyObject?) {         let button = sender as! UIButton         var proxy = textDocumentProxy as! UITextDocumentProxy         if let title = button.titleForState(.Normal) as String? {             switch title {             case "BP":                 proxy.deleteBackward()             case "RETURN":                 proxy.insertText("\n")             case "SPACE":                 proxy.insertText(" ")             case "CHG":                 self.advanceToNextInputMode()             default:                 proxy.insertText(title)             }         }     }  | 
					
2、现在再运行一下你的程序,耶!一切基础功能都完成、完美了!每个特殊按键也都可以正常运作了!
注意:  大小写按键在目前仍无作用,而博主也仍未发现相关方法,欢迎各位补充! 
 
本项目成果预览&实例下载
参考资料
iOS 8 Custom Keyboard Tutorial: How to Create A Third-Party Keyboard Extension
Creating a Custom Keyboard Using iOS 8 App Extension
How to make a custom keyboard in iOS 8 using Swift
GitHub - drewlustro / KeyboardViewController.swift(感谢该作者解决了「Autolayout」的部分问题)


