如何在键盘弹出后将焦点文本字段移动到视图中间 [英] How to move the focussed text field to the middle of the view after keyboard popups

查看:29
本文介绍了如何在键盘弹出后将焦点文本字段移动到视图中间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 iPad 中,我正在创建 SplitView 应用程序.我有一个 UITableVewtable 多行,每行/单元格有三个 UITextField

In my iPad im creating SplitView application. I have a UITableVewtable with multiple rows, each row/cell having three UITextField

当我点击 UITextField 时,一些字段被键盘隐藏了.

When i tap on UITextField some fields are hide by the keyboard.

所以我使用 TPKeyboardAvoidingScrollView 框架,但它不适用于 ios 5.0+.

So im using TPKeyboardAvoidingScrollView framework but it does not works on ios 5.0+.

有时无法滚动表格上的滚动视图.

some times unable to scroll the scroll view on the table.

所以我想每次都将聚焦的单元格移动到键盘的中间/正上方

So I want to move the focussed cell to the middle/ just above the key board at every time

我应该用什么?

提前致谢.

推荐答案

首先打开xib文件,将Content insets(In Scrollview Size)设置为200

First open the xib file and set the Content insets(In Scrollview Size) to 200

现在更新.m文件中的以下两种方法.

Now update following two methods as below in .m file.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cell=@"Cell";        
    Cell *customCell= (Cell *)[tableView dequeueReusableCellWithIdentifier:cell];

    if (customCell==nil) {
        NSArray *bundle = [[NSBundle mainBundle] loadNibNamed:@"Cell" owner:self options:nil];
        for (id object in bundle) {
            if ([object isKindOfClass:[Cell class]])
            {
                customCell = (Cell *)object;
                break;
            }
        }
    }
    customCell.IBTxtfield.tag=indexPath.row;
return customCell;
}

- (void)textFieldDidBeginEditing:(UITextField *)textField{
    NSIndexPath *path=[NSIndexPath indexPathForRow:textField.tag inSection:0];
    [IBtblView scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionTop animated:YES];
}

这篇关于如何在键盘弹出后将焦点文本字段移动到视图中间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆