1. 遇到键盘遮挡怎么办?
回答:给textview找到delegate,并让delegate实现方法
- (void)textViewDidEndEditing:(UITextView *)textView
{
[textView resignFirstResponder];
NSTimeInterval animationDuration = 0.30f;
[UIViewbeginAnimations:@"ResizeForKeyboard"context:nil];
[UIView setAnimationDuration:animationDuration];
self.scrollview.frame =CGRectMake(self.scrollview.frame.origin.x,
self.scrollview.frame.origin.y,
self.scrollview.frame.size.width,
self.scrollview.frame.size.height);
[UIViewcommitAnimations];
return;
}
这样可以让textview所在的view或者scrollview上移,以避开键盘。
2. 使用完键盘后,怎么让键盘自己关闭?
除了设置 self._textView.delegate=self;
还要设置self._textView.returnKeyType=UIReturnKeyDone;
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range
replacementText:(NSString *)text {
if ([text isEqualToString:@"\n"]) {
[textView resignFirstResponder];
return NO;
}
return YES;
}
本文介绍了如何在iOS应用中解决键盘遮挡输入框的问题,通过实现textview代理方法调整scrollView来避开键盘,并提供了关闭键盘的方法。
1万+

被折叠的 条评论
为什么被折叠?



