将UISearchBar锁定到像Game Center这样的UITableView的顶部 [英] Locking a UISearchBar to the top of a UITableView like Game Center

查看:99
本文介绍了将UISearchBar锁定到像Game Center这样的UITableView的顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Game Center中的UITableViews以及它们顶部的搜索栏都有这个很酷的功能。与将搜索栏放在表标题视图中的应用程序(因此它计为标准表格单元格)不同,它似乎用螺栓固定到它上面的父导航栏。
因此,当滚动表格时,搜索栏确实会移动,但如果您在表格边界上方滚动,搜索栏将永远不会停止触摸导航栏。

There's this cool feature in the UITableViews in Game Center and the search bars they have at their tops. Unlike apps where the search bar is placed in the table header view (so it counts as a standard table cell), instead, it seems to be bolted to the parent navigation bar above it. So when scrolling the table, the search bar does indeed move, but if you scroll above the boundaries of the table, the search bar never stops touching the navigation bar.

有谁知道这可能是怎么做的?我想知道Apple是否可能将搜索栏和表放在父卷轴视图中,但我想知道它是否比这更简单。

Does anyone know how this might have been done? I was wondering if Apple maybe placed both the search bar and the table in a parent scroll view, but I'm wondering if it may be simpler than that.

推荐答案

鲍勃的答案是相反的:它应该是MIN(0,scrollView.contentOffset.y)。

Bob's answer is reversed: it ought to be MIN(0, scrollView.contentOffset.y).

另外,为了正确支持调整大小(旋转时会发生),其他帧值应该重复使用。

Also, in order to properly support resizing (which would occur when rotated), the other frame values should be reused.

-(void)scrollViewDidScroll:(UIScrollView *)scrollView 
{
    UISearchBar *searchBar = searchDisplayController.searchBar;
    CGRect rect = searchBar.frame;
    rect.origin.y = MIN(0, scrollView.contentOffset.y);
    searchBar.frame = rect;
}

这篇关于将UISearchBar锁定到像Game Center这样的UITableView的顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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