我有一个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中是靠近botton的文本框:
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;
}
答案 0 :(得分:3)
你需要移动textField。在你的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: