У меня есть обычай UIInputViewController
, назовем его MyInputViewController
. Я установил представление ввода текстового поля в представление одного экземпляра моего контроллера ввода. Вставка, удаление и перемещение курсора отлично работает, когда я вызываю self.dismissKeyboard()
в контроллер представления ввода (метод вызывается, print() записывает в консоль), он ничего не делает.iOS 9 UIInputViewController увольнениеKeyboard
Что может быть неправильным? Это заработало несколько дней назад, но я не мог вспомнить, что может быть ошибкой.
class MyInputController: UIInputViewController {
// SINGLETON:
static let keyboard: MyInputController = MyInputController()
class func setSharedKeyboardForTextField(textField: UITextField) {
textField.inputAccessoryView = nil
textField.inputView = keyboard.view
}
// MARK: initializers
private init() {
super.init(nibName: nil, bundle: nil)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func loadView() {
super.loadView()
self.view.translatesAutoresizingMaskIntoConstraints = false=
}
override func viewDidLoad() {
//set up buttons
}
// MARK: helper functions
func inputText() -> String {
return (self.textDocumentProxy.documentContextBeforeInput ?? "") + (self.textDocumentProxy.documentContextAfterInput ?? "")
}
// MARK: animations
private func grow(sender: MathematicalKeyboardKey) {
sender.superview?.bringSubviewToFront(sender)
UIView.animateWithDuration(0.1) {() -> Void in
sender.transform = scaleTransform
}
}
private func shrink(sender: MathematicalKeyboardKey) {
sender.superview?.sendSubviewToBack(sender)
UIView.animateWithDuration(0.1) {() -> Void in
sender.transform = CGAffineTransformIdentity
}
}
// MARK: actions
func keyTouched(sender: MathematicalKeyboardKey) {
// works
grow(sender)
}
func keyExit(sender: MathematicalKeyboardKey) {
// works
shrink(sender)
}
func resign(sender: MathematicalKeyboardKey) {
// called but doesn't work
dismissKeyboard()
shrink(sender)
}
func keyPressed(sender: MathematicalKeyboardKey) {
// works
self.textDocumentProxy.insertText(sender.insertion)
shrink(sender)
}
func remove(sender: MathematicalKeyboardKey) {
// works
self.textDocumentProxy.deleteBackward()
shrink(sender)
}
func clear(sender: MathematicalKeyboardKey) {
// works
while self.textDocumentProxy.hasText() {
self.textDocumentProxy.deleteBackward()
}
shrink(sender)
}
func moveLeft(sender: MathematicalKeyboardKey) {
// works
self.textDocumentProxy.adjustTextPositionByCharacterOffset(-1)
shrink(sender)
}
func moveRight(sender: MathematicalKeyboardKey) {
// works
self.textDocumentProxy.adjustTextPositionByCharacterOffset(1)
shrink(sender)
}
}
Вы можете ввести полный код? – Xrait
@LGL здесь вы – borchero