iOS 8解除swift的键盘

问题描述 投票:1回答:3

我是swift的初学者,我一直在使用这个dismissKeyboard()方法,但它不适用于键盘扩展。

@IBAction func donePressed (sender: UIButton) {

      dismissKeyboard()


    }

任何人都可以告诉我为什么这不起作用?

谢谢。

编辑:完整的代码

导入UIKit

class KeyboardViewController:UIInputViewController {

var keyboardView: UIView!

@IBOutlet var nextKeyboardButton: UIButton!

override func updateViewConstraints() {
    super.updateViewConstraints()

    // Add custom view sizing constraints here
}

override func viewDidLoad() {
    super.viewDidLoad()

  self.loadInterface()





}


func loadInterface() {

    var keyboardNib = UINib(nibName: "KeyboardView", bundle: nil)

    self.keyboardView = keyboardNib.instantiateWithOwner(self, options: nil)[0] as UIView

    view.addSubview(self.keyboardView)

    view.backgroundColor = self.keyboardView.backgroundColor

    self.nextKeyboardButton.addTarget(self, action: "advanceToNextInputMode", forControlEvents: .TouchUpInside)

    self.nextKeyboardButton.addTarget(self, action: "advanceToNextInputMode", forControlEvents: .TouchUpInside)
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated
}

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.

}

@IBAction func buttonPressed (sender: UIButton) {

    let title = sender.titleForState(.Normal)

    var proxy = textDocumentProxy as UITextDocumentProxy

    proxy.insertText(title!)

}

@IBAction func spacePressed (sender: UIButton) {

    var proxy = textDocumentProxy as UITextDocumentProxy

    proxy.insertText(" ")

}

@IBAction func deletePressed (sender: UIButton) {

    var proxy = textDocumentProxy as UITextDocumentProxy

    proxy.deleteBackward()

}

@IBAction func donePressed (sender: UIButton) {

resignFirstResponder()


}

}

ios iphone swift ios8 keyboard
3个回答
1
投票

试试这样

self.dismissKeyboard()


1
投票

也许试试:

view.endEditing(true)

0
投票

从屏幕上解散自定义键盘。

迅速:

self.dismissKeyboard()

Objective-C的:

[self dismissKeyboard];

https://developer.apple.com/documentation/uikit/uiinputviewcontroller/1618196-dismisskeyboard?language=objc

© www.soinside.com 2019 - 2024. All rights reserved.