Sye*_*eel 4 cocoa-touch objective-c
您好我正在使用表单进行数据输入,一些文本字段位于表单的底部.当我单击文本字段进行写入时,会出现键盘并隐藏字段以使其显示.如果我使textfield第一响应者它隐藏键盘,但通过这样做,我无法做到这一点.我想知道当键盘出现时,整个表格应该按照我的最后一个字段出现在键盘的操作上的方式提前感谢
在滚动视图中添加所有视图并设置滚动视图和文本字段的委托,然后使用这些委托和方法 -
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
[self scrollViewToCenterOfScreen:textField];
return YES;
}
-(BOOL) textFieldShouldReturn:(UITextField *)textField{
if ([textField isEqual:txtField1])
{
[txtField2 becomeFirstResponder];
}
else if ([textField isEqual:txtField2])
{
[txtField3 becomeFirstResponder];
}
else
{
[textField resignFirstResponder];
[scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
}
return YES;
}
- (void)scrollViewToCenterOfScreen:(UIView *)theView {
CGFloat viewCenterY = theView.center.y;
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
CGFloat availableHeight = applicationFrame.size.height - 200; // Remove area covered by keyboard
CGFloat y = viewCenterY - availableHeight / 2.0;
if (y < 0) {
y = 0;
}
[scrollView setContentOffset:CGPointMake(0, y) animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2802 次 |
最近记录: |