您好我遇到了UITextView
的问题。
在我的应用程序中,我需要同时支持Portrait和Landscape。
所以我将UITextView
添加到我的应用中,并在键盘出现时使用以下代码调整UITextView
的框架大小,因为当键盘出现时,UITextView
在键盘后面,我不能看看我在UITextView
写的内容。
- (void)keyboardWillShow:(NSNotification*)notification
{
[self moveTextViewForKeyboard:notification up:YES];
}
- (void)keyboardWillHide:(NSNotification*)notification
{
[self moveTextViewForKeyboard:notification up:NO];
}
- (void)moveTextViewForKeyboard:(NSNotification*)notification up:(BOOL)up {
NSDictionary *userInfo = [notification userInfo];
NSTimeInterval animationDuration;
UIViewAnimationCurve animationCurve;
CGRect keyboardRect;
[[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&animationCurve];
animationDuration = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
keyboardRect = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
keyboardRect = [self.view convertRect:keyboardRect fromView:nil];
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:animationDuration];
[UIView setAnimationCurve:animationCurve];
if (up == YES)
{
CGFloat keyboardTop = keyboardRect.origin.y;
CGRect newTextViewFrame = self.txtView.frame;
newTextViewFrame.size.height = keyboardTop - self.txtView.frame.origin.y - 10;
self.txtView.frame = newTextViewFrame;
}
else
{
self.txtView.frame = originalCGRect;
}
[UIView commitAnimations];
}
当键盘出现并且不再覆盖我的UITextView
时,这很好。
然而,当我旋转到横向时,UITextView
框架不再正确,而且当我隐藏键盘时,它仍然保持像小尺寸而不适合View。
我该如何解决这个问题?
请帮帮我。
答案 0 :(得分:1)
试试这个我希望对你有帮助....