In iOS, the general TextField can display a navigation text, there is placeholder (placeholder, used to display the message), TextView can display multiple lines of text but there is no placeholder this, the following method can solve the problem.
@interface Personsetviewcontroller () <UITextViewDelegate>
Compliance with agency agreements
-(void) Viewdidload {
[Super Viewdidload];
Two TextView to display placeholder at the bottom, set them to non-editable
[_farmnametextview Seteditable:no];
[_farmdiscribetextview Seteditable:no];
Two TextView for user input on top, set self as proxy
Self.farmNameTView.delegate =self;
Self.farmDiscrebeTView.delegate =self;
}
The method used to implement
-(BOOL) TextView: (Uitextview *) TextView Shouldchangetextinrange: (nsrange) Range Replacementtext: (NSString *) text{
if (![ Text isequaltostring:@ ""])//If text is not empty, then hide the following two TextView
{
[_farmnametextview Sethidden:yes];
[_farmdiscribetextview Sethidden:yes];
}
If the character is empty and the cursor is in the first position, and there are no characters, then the following two TextView are displayed
if ([Text isequaltostring:@ ""] && range.length==1 && range.location==0) {
[_farmnametextview Sethidden:no];
[_farmdiscrebetview Sethidden:no];
}
If you encounter \ n (enter), then close the keyboard
if ([text isequaltostring:@ "\ n"]) {
[TextView Resignfirstresponder];
return NO; Status is not editable
}
return YES; Status for Edit
}
When the keyboard appears, you need to move the original view upward, with animation to achieve the effect
Start editing
-(void) textviewdidbeginediting: (Uitextview *) textview{
[UIView Beginanimations:nil Context:nil]; Animation start
[UIView setanimationduration:0.2];//animation duration 0.2 sec.
[UIView Setanimationbeginsfromcurrentstate:yes]; Set the animation to start from the current state
Self.datascrollview.frame=cgrectmake (0, 0, cgrectgetwidth (self.dataScrollView.frame), Cgrectgetheight ( Self.dataScrollView.frame)); Set the frame of the view in edit state
[UIView commitanimations]; Submit Animation
}
End Edit
-(void) textviewdidendediting: (Uitextview *) textview{
[UIView Beginanimations:nil Context:nil];
[UIView setanimationduration:0.2];
[UIView Setanimationbeginsfromcurrentstate:yes];
Self.datascrollview.frame=cgrectmake (0, 133, Cgrectgetwidth (Self.dataScrollView.frame), Cgrectgetheight ( Self.dataScrollView.frame)); Set the frame of the view in a non-editable state
[UIView commitanimations];
}
iOS Settings TextView placeholder