键盘阻止我的看法
问题描述:
我有一个UIView与其中的另一个UIView。在里面的UIView有我要填写一个文本框当我尝试以填补它在键盘块我的观点:键盘阻止我的看法
的UIViewController中有以下
containerView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.view=containerView;
//The apropriate releases etc are further on...
当我触摸它时,键盘按预期方式出现,但会阻止我试图填充的文本框。如何强制视图向上滑动?
前视图
OptionsFront * fv = [[OptionsFront alloc] initWithFrame:[UIScreen mainScreen].bounds];
[containerView addSubview:frontView];
在正视图是一个子视图
CGRect bounds = CGRectMake(0.0f, 210.0f, 280.0f, 130.0f);
sv = [[UIView alloc] initWithFrame:bounds];
[self addSubview:sv]; //added to frontView
在SV是钮附近的文本框:
rect = CGRectMake(70.0f, 20.0f, 100.0f, 27.0f);
cf = [self createTextField_Rounded:rect holder:@"+ve"];
[sv addSubview:cf];
所以CF恰好是近页面的底部。我预计当我选择它时,整个显示屏会向上移动,但键盘只是向上移动并阻止它。
我该怎么办?
附录:
- (UITextField *)createTextField_Rounded:(CGRect) frame holder:(NSString *) ph
{
UITextField *returnTextField = [[UITextField alloc] initWithFrame:frame];
returnTextField.borderStyle = UITextBorderStyleRoundedRect;
returnTextField.textColor = [UIColor blackColor];
returnTextField.font = [UIFont systemFontOfSize:17.0];
returnTextField.delegate = self;
returnTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
returnTextField.returnKeyType = UIReturnKeyDone;
returnTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
return returnTextField;
}
答
你需要移动文本框起来。在你的UITextField委托执行类似(从内存中):
- (void)textFieldDidBeginEditing:(UITextField *)textField {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
textField.superview.frame = CGRectMake(0.0f, 100.0f, 280.0f, 130.0f); // experiment with frame size
[UIView commitAnimations];
}
,你会想要将它移回在textFieldDidEndEditing:
谢谢!很优雅的解决方案 – 2010-04-22 18:36:40