Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 表视图未正确调整到键盘_Ios_Uitableview_User Interface_Uikeyboard_Uiedgeinsets - Fatal编程技术网

Ios 表视图未正确调整到键盘

Ios 表视图未正确调整到键盘,ios,uitableview,user-interface,uikeyboard,uiedgeinsets,Ios,Uitableview,User Interface,Uikeyboard,Uiedgeinsets,我有一个自定义继承的UIView类,其中只有一个子视图是UITableView。当显示键盘时,我试图模拟UITableViewController的正常功能,以将表视图的contentInset和滚动指示符集调整到键盘的高度。这是我的方法,当键盘确实从我的自定义UIView类中显示时调用该方法: - (void)keyboardDidShow:(NSNotification*)notification { NSDictionary* info = [notification userIn

我有一个自定义继承的
UIView
类,其中只有一个子视图是
UITableView
。当显示键盘时,我试图模拟
UITableViewController
的正常功能,以将表视图的
contentInset
滚动指示符集调整到键盘的高度。这是我的方法,当键盘确实从我的自定义
UIView
类中显示时调用该方法:

- (void)keyboardDidShow:(NSNotification*)notification
{
    NSDictionary* info = [notification userInfo];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
    _tableView.contentInset = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
    _tableView.scrollIndicatorInsets = _tableView.contentInset;
}
这在一定程度上是可行的,但由于某种原因,键盘在表视图上仍有一些重叠,大约有10个像素


我认为这与没有考虑其他屏幕几何结构有关,但我不明白这是怎么回事。键盘的高度应该正是我所需要的,因为tableView一直延伸到屏幕的底部。有什么想法吗?

更改tableView.frame.size.height,以考虑键盘

显示键盘时,降低高度, 未显示时,请增加高度

如果要考虑所有可能的键盘高度

,请参阅此。 不要弄乱contentInset和Scroll指示符号集。只需设置帧大小即可为您解决这些问题

你的方法应该是这样的

- (void)keyboardDidShow:(NSNotification*)notification
{
    NSDictionary* info = [notification userInfo];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
    CGRect rect = _tableView.frame;
    rect.size.height = _tableView.frame.size.height - kbSize.height;
    _tableView.frame = rect;
}

- (void)keyboardWillHide:(NSNotification*)notification
{
    NSDictionary* info = [notification userInfo];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
    CGRect rect = _tableView.frame;
    rect.size.height = _tableView.frame.size.height + kbSize.height;
    _tableView.frame = rect;
}

我已经将这段代码用于类似的功能。因此,如果它仍然不工作,则会出现其他问题。

更改tableView.frame.size.height以说明键盘的问题

显示键盘时,降低高度, 未显示时,请增加高度

如果要考虑所有可能的键盘高度

,请参阅此。 不要弄乱contentInset和Scroll指示符号集。只需设置帧大小即可为您解决这些问题

你的方法应该是这样的

- (void)keyboardDidShow:(NSNotification*)notification
{
    NSDictionary* info = [notification userInfo];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
    CGRect rect = _tableView.frame;
    rect.size.height = _tableView.frame.size.height - kbSize.height;
    _tableView.frame = rect;
}

- (void)keyboardWillHide:(NSNotification*)notification
{
    NSDictionary* info = [notification userInfo];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
    CGRect rect = _tableView.frame;
    rect.size.height = _tableView.frame.size.height + kbSize.height;
    _tableView.frame = rect;
}

我已经将这段代码用于类似的功能。因此,如果它仍然不起作用,那就是出了问题。

我很好奇为什么这对你不起作用,因为我有基本相同的东西,它对我起作用。我只看到一个区别,我不访问“\u tableView”,而是确保始终使用getter和setter

这就是我所做的,那就是工作

- (void)keyboardDidShow:(NSNotification *)keyboardNotification
{
    NSDictionary *info = [keyboardNotification userInfo];
    CGSize keyboardSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;

    CGFloat newBottomInset = 0.0;

    UIEdgeInsets contentInsets;
    if (UIDeviceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]) ) {
        newBottomInset = keyboardSize.height;
    } else {
        newBottomInset = keyboardSize.width;
    }

    contentInsets = UIEdgeInsetsMake(0.0, 0.0, newBottomInset, 0.0);
    self.tableView.contentInset = contentInsets;
    self.tableView.scrollIndicatorInsets = contentInsets;
}
请注意,我的应用程序允许设备旋转,当这种情况发生时,使用的值需要是键盘的宽度,因为这些值是相对于纵向方向的,这让我困惑了好几个小时


希望
self.tableView
access会有所不同。

我很好奇为什么这对您不起作用,因为我基本上有相同的东西,它对我也起作用。我只看到一个区别,我不访问“\u tableView”,而是确保始终使用getter和setter

这就是我所做的,那就是工作

- (void)keyboardDidShow:(NSNotification *)keyboardNotification
{
    NSDictionary *info = [keyboardNotification userInfo];
    CGSize keyboardSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;

    CGFloat newBottomInset = 0.0;

    UIEdgeInsets contentInsets;
    if (UIDeviceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]) ) {
        newBottomInset = keyboardSize.height;
    } else {
        newBottomInset = keyboardSize.width;
    }

    contentInsets = UIEdgeInsetsMake(0.0, 0.0, newBottomInset, 0.0);
    self.tableView.contentInset = contentInsets;
    self.tableView.scrollIndicatorInsets = contentInsets;
}
请注意,我的应用程序允许设备旋转,当这种情况发生时,使用的值需要是键盘的宽度,因为这些值是相对于纵向方向的,这让我困惑了好几个小时


希望
self.tableView
access能起到作用。

我正在讲一个关于管理键盘的苹果文档中给出的例子。查看位于键盘部分下的移动内容。在这里你可以看到苹果公司推荐使用插图。不过,我确实尝试过你的解决方案。同样的问题,但现在我可以清楚地看到,键盘返回的高度是不够的。下面是一个合成图,显示了当我用键盘返回的高度减去帧时,帧的外观。有趣的是,返回的高度是216,这是苹果公司说的应该是。我有点迷路了。这是我的合成图:安娜提到键盘高度为216,这也是我在肖像模式下看到的。我想知道她的“合成”是不是使用了图片上的像素,而没有考虑到这些值是以点(不是像素)为单位的。试试revealapp.com。下载测试版,你可以在模拟器上看到你的应用程序实际发生了什么。当表格视图受到布局限制时,这能起作用吗?我正在讲苹果公司关于管理键盘的文档中给出的一个例子。查看位于键盘部分下的移动内容。在这里你可以看到苹果公司推荐使用插图。不过,我确实尝试过你的解决方案。同样的问题,但现在我可以清楚地看到,键盘返回的高度是不够的。下面是一个合成图,显示了当我用键盘返回的高度减去帧时,帧的外观。有趣的是,返回的高度是216,这是苹果公司说的应该是。我有点迷路了。这是我的合成图:安娜提到键盘高度为216,这也是我在肖像模式下看到的。我想知道她的“合成”是不是使用了图片上的像素,而没有考虑到这些值是以点(不是像素)为单位的。试试revealapp.com。下载测试版,你可以在模拟器上看到你的应用程序实际发生了什么。当表格视图受到布局限制时,这是否有效?