另一种对“键盘模糊UITextField”的看法问题 [英] Another take on the "keyboard obscures UITextField" problem

查看:76
本文介绍了另一种对“键盘模糊UITextField”的看法问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一个常见的问题,UITableViewController修复了这个是iPhone SDK 3.0,但是UITableViewController没有按照我的预期工作,可能是因为我正在使用它。这是我的问题:

I know that this is a common problem and the UITableViewController fixed this is iPhone SDK 3.0, but the UITableViewController is not working as I expect, probably due to how I am using it. Here's my problem:

我正在处理一个表格,该表格在一个分组表格中,其中包含一些文本字段。
表格下半部分被键盘遮挡。我知道这是一个古老的问题,并且有一些代码可以自动滚动,但我还有一些要添加的内容,并且想知道是否有人发现了这个问题并修复了它。

I'm working on a form, which is in a grouped table, which contains some text fields. Those on the lower part of the form get obscured by the keyboard. I know this is an age-old problem, and there are some examples of code to auto scroll, but I've a little bit more to add, and was wondering if anyone has found this, and fixed it.

首先:从3.0开始,如果你的表由UITableViewController控制,你就可以自动滚动它。我试过了,确实它确实有效。
但是,我想使用自定义背景图像,UITableViewController不与它一起玩。这就是我所做的:

Firstly: Since 3.0, if your table is controlled by a UITableViewController, you get this scrolling automagically. I've tried it and indeed it does work. However, I want to use a custom background image, which UITableViewController doesn't play ball with. Here's what I've done:


  1. 创建一个带有图像的普通视图的XIB。

  2. 同样在XIB内部,我有一个UIViewController(实际上是我编写数据源方法时我自己的子类等),它有表格。

  3. 在我的主视图viewDidLoadMethod我试过这个:
    tableViewController.view.backgroundColor = [UIColor clearColor];
    [self.view addSubview:tableViewController.view];

事实上,该表显示为我期望它看。
但是,当我点击表格中的文本字段时,我没有得到tableViewController给我免费的魔术滚动。

And indeed, the table shows up as I expect it to look. However, when I tap on a text field in the table, I'm not getting the "magic" scrolling that the tableViewController is meant to give me for free.

就目前而言,它与我完全不使用TableViewController的行为完全相同,并将表直接删除到imageView上。 (坦率地说,这样可以减少1个类,并且更容易阅读代码)。

As it stands, it is the exact same behaviour as I didn't use a TableViewController at all, and dropped the table directly onto the imageView. (Which, frankly, makes for 1 less class, and easier to read code).

我引入TableViewController的唯一原因是让这个自动滚动。

The only reason I introduced a TableViewController was to get this auto-scrolling.

我缺少什么?

推荐答案

调整大小;如果你想要它平滑然后使用动画块。

Resize it; if you want it smooth then use animation block.

[UIView beginAnimations:@"tableAnim" context:nil];
// 214 = keyboard size, adjust it if you have navigation bar or status bar
tableView.frame = CGRectMake(0, 0, 320, 480 - 214);
[UIView commitAnimations];

这篇关于另一种对“键盘模糊UITextField”的看法问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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