我有一个文本字段和两个textViews ...当写入1中的内容时控制键盘加速...但是当我想转移另一个控件时我的键盘不让我写,因为它覆盖了整个查看...我可以解决我的问题吗?
答案 0 :(得分:1)
您应该向上移动视图,以便键盘不覆盖textfield / textview。像这样......
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
if (textField == *textFieldName*)
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
self.view.frame = CGRectMake(self.view.frame.origin.x, (self.view.frame.origin.y - 65.0), self.view.frame.size.width, self.view.frame.size.height);
[UIView commitAnimations];
}
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
if (textField == *textFieldName*)
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
self.view.frame = CGRectMake(self.view.frame.origin.x, (self.view.frame.origin.y + 65.0), self.view.frame.size.width, self.view.frame.size.height);
[UIView commitAnimations];
}
}
并且对于textView使用:
- (void)textViewDidBeginEditing:(UITextView *)textView
和
- (void)textViewDidEndEditing:(UITextView *)textView
答案 1 :(得分:0)
使用为uitextview和uitextfiled ....
提供的委托功能答案 2 :(得分:0)
- (void) animateTextField: (UITextField*) textField up: (BOOL) up
{
const int movementDistance = 150; // tweak as needed
const float movementDuration = 0.3f; // tweak as needed
int movement = (up ? -movementDistance : movementDistance);
[UIView beginAnimations: @"anim" context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: movementDuration];
self.view.frame = CGRectOffset(self.view.frame, 0, movement);
[UIView commitAnimations];
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
[self animateTextField: textField up: YES];
}
- (void)textViewDidEndEditing:(UITextView *)textView{
[self animateTextField: textField up: NO];
}
答案 3 :(得分:0)
您可以将整个视图向上移动,或者只是将控件(文本字段和文本视图)向上移动..或者使视图可滚动,以便用户可以在键盘可见时向下滚动。