Swift-uitextfield turn off the soft keyboard after completing the input

Source: Internet
Author: User
Tags uicontrol

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.