The iphone pops up the keyboard and the text box automatically moves up.

Source: Internet
Author: User

1.
Let class inherit Uitextviewdelegate


Uitextview *inputtextview;
Uiscrollview * _scrollview;


2. Create the ScrollView in the INIT function first
_scrollview = [[Uiscrollview alloc] Initwithframe:cgrectmake (0, 0, 320, 416)];
[Self.view Addsubview:_scrollview];




Inputtextview = [[Uitextview alloc] Initwithframe:cgrectmake (Nstarty, 290, 110)];
[Inputtextview Setfont:[uifont systemfontofsize:15];
Inputtextview.backgroundcolor = [Uicolor Clearcolor];
Inputtextview.delegate = self;
Inputtextview.returnkeytype = Uireturnkeydone;
[_scrollview Addsubview:inputtextview];




3.


#pragma mark-
#pragma Mark Textviewdelegate


-(BOOL) TextView: (Uitextview *) TextView Shouldchangetextinrange: (nsrange) Range Replacementtext: (NSString *) Text {
When you click on keyboard done, close the keyboard
if ([text isequaltostring:@ "\ n"]) {
[TextView Resignfirstresponder];
return NO;
}

return YES;
}


-(void) textviewdidbeginediting: (Uitextview *) TextView
{
[UIView Beginanimations:nil Context:nil];
_scrollview.frame = CGRectMake (0,-80, 320, 416);
[UIView commitanimations];
}


-(void) textviewdidendediting: (Uitextview *) TextView
{
[UIView Beginanimations:nil Context:nil];
_scrollview.frame = CGRectMake (0, 0, 320, 416);
[UIView commitanimations];
}

The iphone pops up the keyboard and the text box automatically moves up.

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.