summed up the following ways, welcome to add
1, bind touch up inside event for blank area
2, overriding the touchesended method
3, bind did End on Exit event for TextField
One, turn off when you click outside the edit area (space zone binding Touch up Inside event )
Create a new project, open Main.storyboard, add a text Field, make a connection to Viewcontroller, and then click in the blanks to change the custom class class to Uicontrol in the right window.
then bind the touch up inside event for Uicontrol (You can bind an event only after you change to Uicontrol)
Viewcontroller:
Import Uikitclass Viewcontroller:uiviewcontroller { @IBOutlet var name:uitextfield! Override Func Viewdidload () { super.viewdidload () //Do any additional setup after loading the view, typically fro M a nib. } Override Func didreceivememorywarning () { super.didreceivememorywarning () //Dispose of any of the resources that can be recreated. } @IBAction func Closekeyboard (sender:anyobject) { name.resignfirstresponder (); } }
Second, click outside the editing area when you close (rewrite touchesended)
You just need to rewrite the touchesended method in Viewcontroller.
Touch events when one or more fingers leave the screen triggering the override Func touchesended (touches:set<nsobject>, withevent event:uievent) { Name.resignfirstresponder (); }
Third, click on the Done/go/next in the lower right corner of the soft keyboard ... Turn off the keyboard (the Do End on Exit event is bound for TextField)
Select the Main.storyboard in the Text Field, Control-drag-and-hold to bind the Do End on Exit event
@IBAction func Doneclosekeyboard (sender:anyobject) { name.resignfirstresponder (); }
Swift-uitextfield turn off the soft keyboard after completing the input