カーソル移動ボタンを作成していますが、文末ボタンだけ反応しません。
どこが悪いかわからないので、どなたか教えて下さい。
import UIKit
class KeyboardViewController: UIInputViewController {
//@IBOutlet var nextKeyboardButton: UIButton!
var keyboardView: KeyboardView = KeyboardView()
override func updateViewConstraints() {
super.updateViewConstraints()
// Add custom view sizing constraints here
}
override func viewDidLoad() {
super.viewDidLoad()
self.keyboardView = Bundle.main.loadNibNamed("KeyboardView", owner: nil, options: nil)?.first as! KeyboardView
self.keyboardView.bounds = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 250)
self.addGestureToKeyboard()
self.inputView = self.keyboardView
// Perform custom UI setup here
// self.nextKeyboardButton = UIButton(type: .system)
//
// self.nextKeyboardButton.setTitle(NSLocalizedString("Next Keyboard", comment: "Title for 'Next Keyboard' button"), for: [])
// self.nextKeyboardButton.sizeToFit()
// self.nextKeyboardButton.translatesAutoresizingMaskIntoConstraints = false
//
// self.nextKeyboardButton.addTarget(self, action: #selector(handleInputModeList(from:with:)), for: .allTouchEvents)
//
// self.view.addSubview(self.nextKeyboardButton)
//
// self.nextKeyboardButton.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
// self.nextKeyboardButton.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
}
override func viewWillLayoutSubviews() {
//self.nextKeyboardButton.isHidden = !self.needsInputModeSwitchKey
super.viewWillLayoutSubviews()
}
override func textWillChange(_ textInput: UITextInput?) {
// The app is about to change the document's contents. Perform any preparation here.
}
override func textDidChange(_ textInput: UITextInput?) {
// The app has just changed the document's contents, the document context has been updated.
var textColor: UIColor
let proxy = self.textDocumentProxy
if proxy.keyboardAppearance == UIKeyboardAppearance.dark {
textColor = UIColor.white
} else {
textColor = UIColor.black
}
//self.nextKeyboardButton.setTitleColor(textColor, for: [])
}
fileprivate func addGestureToKeyboard() {
self.keyboardView.initialButton.addTarget(self,
action: #selector(pressInitialKey),
for: .touchUpInside)
self.keyboardView.bacKButton.addTarget(self,
action: #selector(pressBackKey),
for: .touchUpInside)
self.keyboardView.proceedButton.addTarget(self,
action: #selector(pressProceedKey),
for: .touchUpInside)
self.keyboardView.endButton.addTarget(self,
action: #selector(pressEndKey),
for: .touchUpInside)
self.keyboardView.globe.addTarget(self, action: #selector(handleInputModeList(from:with:)), for: .allTouchEvents)
}
@objc fileprivate func pressInitialKey() {
self.textDocumentProxy.adjustTextPosition(byCharacterOffset: -(self.textDocumentProxy.documentContextBeforeInput?.count ?? 0))
}
@objc fileprivate func pressBackKey() {
self.textDocumentProxy.adjustTextPosition(byCharacterOffset: -1)
}
@objc fileprivate func pressProceedKey() {
self.textDocumentProxy.adjustTextPosition(byCharacterOffset: 1)
}
@objc fileprivate func pressEndKey() {
let str = self.textDocumentProxy.selectedText
self.textDocumentProxy.adjustTextPosition(byCharacterOffset: 99)
}
fileprivate func keyPressed(key: UIButton) {
self.textDocumentProxy.insertText(key.currentTitle!)
}
}