In IOS development, TextView as a child control, click Enter text, and then exit the text way

Source: Internet
Author: User

Mode 1. Use gestures and notifications to monitor the keyboard using the pop-up keyboard when double-clicking the input

The code is as follows:

1. Monitor keyboard notifications

[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (ADDTAP) Name: Uikeyboarddidshownotification Object:nil];

[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (KEYDISMISS) Name: Uikeyboardwillhidenotification Object:nil];

2. Add a method to the pop-up keyboard

-(void) Addtap {

_tap = [[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (resign)];

[Self.view Addgesturerecognizer:_tap];//self.view can be changed depending on the situation

}

3. Gestures of events

#pragma mark-click Gesture Event method

-(void) resign {

[Self.view Endediting:yes];

}

4. How the keyboard disappears

-(void) Keydismiss {

[Self.view Removegesturerecognizer:_tap];

}

Method 2: Using the TextView proxy method

Proxy methods for #pragma mark-textview

-(BOOL) TextView: (Uitextview *) TextView Shouldchangetextinrange: (nsrange) Range Replacementtext: (NSString *) Text {

if ([text isequaltostring:@ "\ n"]) {

[TextView Resignfirstresponder];

return NO;

}

return YES;

}

In IOS Development, click Enter text as a child control, and then exit the text TextView

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.