If we set the return key of the text box to done, then we associate the Do End on Exit event of the text box in the code with storyboard. The Resignfirstresponder () method of the text box is called in the associated code. You can enable the user to turn off the virtual keyboard when they click on the keyboard return key.
You can also turn off the virtual keyboard if you want to implement a stage screen other than when the user taps the text box. This is where the background of the screen responds to the touch down event. (1) Because the background is a UIView control, you cannot drag the associated touch event directly. The first step is to make the background a Uicontrol control. Click the Show the Identity Inspector icon in the upper-right corner and set the custom class class to Uicontrol to associate with the event.
(2) Drag the background into the code to associate the touch up inside event
(3) In the background click event, turn off the virtual keyboard
123456789101112131415161718 |
import UIKit
class ViewController
:
UIViewController {
@IBOutlet weak var tf:
UITextField
!
override func viewDidLoad() {
super
.viewDidLoad()
}
@IBAction func viewClick(sender:
AnyObject
) {
tf.resignFirstResponder()
}
override func didReceiveMemoryWarning() {
super
.didReceiveMemoryWarning()
}
}
|
Swift-click the external screen of the input box to close the virtual keyboard