I have a big comment field, which is a UITextView
. Since the keyboard appears, and the UITextField is nearly half of the whole view, users can hardly see the field. What I want to do is when the keyboard appears, (i.e. the UITextView
is editing) I want to shift the view up to make it completely visible, and user friendly.
Asked
Active
Viewed 952 times
0

Bartu
- 2,189
- 2
- 26
- 50
2 Answers
0
You can use the
UITextViewTextDidBeginEditing
to rearrange items in your view. And use
– bringSubviewToFront:
to bring the textview to the front.

apple16
- 1,137
- 10
- 13
-
no, `– bringSubviewToFront:` does not move anything in front of the keyboard. Nothing can do that, actually. – apple16 May 27 '12 at 20:37
-
OK, in the `UITextViewTextDidBeginEditing` method, move the text box to the top of the screen, bring it overtop of everything else, and call `-becomeFirstResponder` if you have to, and on the end editing method move it back to where it was. – apple16 May 27 '12 at 21:38
0
After looking through complicated and useless codes, I found a quick solution here:
https://stackoverflow.com/a/5221243/1139419
This answer here handles this situation very gently, thanks to Dan Ray
A quick note regarding: Calling this function not quite did the charm for me
-(void)scrollToView:(UIView *)view {
CGRect theFrame = view.frame;
float y = theFrame.origin.y - 15;
y -= (y/1.7);
[self scrollToY:-y];
}
so I edited this function:
-(void)scrollToView:(UIView *)view withCoefficient:(CGFloat)coeff
{
CGRect theFrame = view.frame;
float y = theFrame.origin.y;
y -= (y/coeff);
[self scrollToY:-y];
}
into this. This way I can try which coefficient for sliding my main view is proper. Instead of 1.7, 2 did the charm for me. Please visit the link for full solution. Also note that you might want to apply same thing for your UINavigationController
as well, if exists;
-(void)textViewDidBeginEditing:(UITextView *)textView
{
[self.view scrollToView:textView withCoefficient:2.0];
[self.navigationController.view scrollToView:textView withCoefficient:2.0];
}