平滑过渡到“全屏”使用 UISearchDisplayController 时
为了解释我正在寻找的内容,我将举一个例子:在“联系人”应用程序中,当您单击表视图第一行中的“搜索”字段时,它将顺利占据整个屏幕(不包括状态栏),包括导航控制器的标题栏。
编辑:我还意识到,我很确定这与 UITableView 中的 UISearchDisplayController 相关,而 UITableView 位于 TabBarController 中的 NavigationController 中。问题是搜索显示只会占用表格视图大小,而不占用导航控制器。
我在程序中通过使用 UIView 动画并调整整个导航控制器框架的大小以在可见屏幕视图上方开始来模仿这一点。见下文:
-(void)SetNavContTitleVis:(BOOL)ishidden {
[UIView beginAnimations:@"frame" context:nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration: 0.3];
CGRect frameIn;
if (ishidden) {
frameIn = CGRectMake(0,-46,320,480);
} else {
frameIn = CGRectMake(0,0,320,480-46);
}
self.parentViewController.view.frame=frameIn
[UIView commitAnimations];
}
这工作得很好并且完成了工作,但感觉就像是黑客攻击。有没有更简单的方法来使用搜索显示控制器来做到这一点?我觉得这是一个黑客,如果显示尺寸发生变化或苹果平板电脑出现等,将来会给我带来麻烦。我已经环顾了一段时间,但没有找到任何简单的设置来强制 UISearchDisplayController顺利占据导航控制器的标题栏。
To explain what I'm looking for I'll give an example: In the Contacts app, when you click the Search field in the first row of the table view it will smoothly take over the entire screen (minus the status bar) including the Navigation Controller's title bar.
Edit: I've also realized that I'm pretty sure this is related to the UISearchDisplayController being within a UITableView which is within an NavigationController which is within a TabBarController. The problem is that the search display will only take up the tableviews size and not the navigation controller.
I've mimicked this in my program by using UIView animations and resizing the entire navigation controller's frame to start above the visible screen's view. See below:
-(void)SetNavContTitleVis:(BOOL)ishidden {
[UIView beginAnimations:@"frame" context:nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration: 0.3];
CGRect frameIn;
if (ishidden) {
frameIn = CGRectMake(0,-46,320,480);
} else {
frameIn = CGRectMake(0,0,320,480-46);
}
self.parentViewController.view.frame=frameIn
[UIView commitAnimations];
}
This works fine and gets the job done but it feels like a hack. Is there any simpler way to do this with search display controllers? I feel that this is a hack that will get me into trouble in the future if display sizes change or the Apple tablet comes out etc. I've looked around for a while but haven't found any simple setting that will force the UISearchDisplayController to take up the navigation controller's title bar smoothly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,搜索栏应该有这样的动画。查看 Apple 的示例 TableSearch。
The search bar should animate like that by default. Check out Apple's sample TableSearch.