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.