iPhone SDK:设置 UISearchDisplayController 的表格视图的大小

发布于 2024-08-23 14:25:35 字数 1165 浏览 5 评论 0原文

我的应用程序的表格视图不占据整个屏幕高度,因为我允许底部有 50 像素的横幅。

当我开始在搜索栏中输入内容时,搜索结果表格视图会变大;它填充了搜索栏和选项卡栏之间的所有可用屏幕空间。这意味着最后的搜索结果被横幅遮盖了。

如何指定 UISearchDisplayController 使用的表视图的大小?我看不到任何边界或框架属性。

编辑添加屏幕:

这就是在 IB 中设置表视图的方式。它结束于合成标签栏 50px 处。

替代文本
(来源:lightwood.net

这是内容显示正常。我已经滚动到这里的最底部。 替代文本
(来源:lightwood.net

就是这样搜索时显示。我再次滚动到最底部。如果我禁用横幅广告,我可以看到搜索显示表直接向下延伸到标签栏。

替代文本
(来源:lightwood.net

My app's table view does not occupy the full screen height, as I've allowed 50px at the bottom for a banner.

When I begin typing in the search bar, the search results table view is larger; it fills all available screen space between the search bar and the tab bar. This means that the very last search result is obscured by the banner.

How do I specify the size of the table view used by UISearchDisplayController? There's no bounds or frame property that I can see.

EDIT TO ADD SCREENSHOTS:

This is how the table view is set up in IB. It ends 50px short of the synthesized tab bar.

alt text
(source: lightwood.net)

This is how content displays normally. I've scrolled to the very bottom here.
alt text
(source: lightwood.net)

This is how it displays when searching. Again, I've scrolled to the very bottom. If I disable the banner ad, I can see that the search display table spreads right down to the tab bar.

alt text
(source: lightwood.net)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

森林迷了鹿 2024-08-30 14:25:35

解决这个问题的关键是找出何时更改表格视图的几何形状。 调用

[self.searchDisplayController.searchResultsTableView setFrame:someframe];

创建 UISearchDisplayController 之后 是徒劳的。答案是这个委托方法:

-(void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView {
    tableView.frame = someframe;
}

注意,我也尝试过 -searchDisplayController:didLoadSearchResultsTableView 但它在那里没有什么好处。您必须等到它显示才能调整其大小。

另请注意,如果您简单地指定tableView.frame = otherTableView.frame,则搜索结果表格会与其相应的搜索栏重叠,因此无法清除或取消搜索!

我的最终代码如下所示:

-(void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView {

    CGRect f = self.masterTableView.frame;  // The tableView the search replaces
    CGRect s = self.searchDisplayController.searchBar.frame;
    CGRect newFrame = CGRectMake(f.origin.x,
                                 f.origin.y + s.size.height,
                                 f.size.width,
                                 f.size.height - s.size.height);

    tableView.frame = newFrame;
}

The key to solving this one was finding out when to change the geometry of the table view. Calling:

[self.searchDisplayController.searchResultsTableView setFrame:someframe];

after creating the UISearchDisplayController was futile. The answer was this delegate method:

-(void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView {
    tableView.frame = someframe;
}

Note, I had also tried -searchDisplayController:didLoadSearchResultsTableView but it did no good in there. You have to wait until it's displayed to resize it.

Also note that if you simply assign tableView.frame = otherTableView.frame, the search results table overlaps its corresponding search bar, so it is impossible to clear or cancel the search!

My final code looked like this:

-(void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView {

    CGRect f = self.masterTableView.frame;  // The tableView the search replaces
    CGRect s = self.searchDisplayController.searchBar.frame;
    CGRect newFrame = CGRectMake(f.origin.x,
                                 f.origin.y + s.size.height,
                                 f.size.width,
                                 f.size.height - s.size.height);

    tableView.frame = newFrame;
}
纵情客 2024-08-30 14:25:35

我更新了代码以允许更深的视图层次结构,但半透明封面视图的初始框架仍然占据搜索栏下方的整个窗口。

-(void)searchDisplayController: (UISearchDisplayController*)controller 
 didShowSearchResultsTableView: (UITableView*)tableView 
{
    if ( [controller.searchBar.superview isKindOfClass: [UITableView class]] )
    {
        UITableView* staticTableView = (UITableView*)controller.searchBar.superview;

        CGRect f = [tableView.superview convertRect: staticTableView.frame fromView: staticTableView.superview];
        CGRect s = controller.searchBar.frame;
        CGRect newFrame = CGRectMake(f.origin.x,
                                     f.origin.y + s.size.height,
                                     f.size.width,
                                     f.size.height - s.size.height);

        tableView.frame = newFrame;
    }
}

I updated the code to allow for deeper view hierarchies, but the initial frame of the semi-transparent cover view still takes up the entire window below the search bar.

-(void)searchDisplayController: (UISearchDisplayController*)controller 
 didShowSearchResultsTableView: (UITableView*)tableView 
{
    if ( [controller.searchBar.superview isKindOfClass: [UITableView class]] )
    {
        UITableView* staticTableView = (UITableView*)controller.searchBar.superview;

        CGRect f = [tableView.superview convertRect: staticTableView.frame fromView: staticTableView.superview];
        CGRect s = controller.searchBar.frame;
        CGRect newFrame = CGRectMake(f.origin.x,
                                     f.origin.y + s.size.height,
                                     f.size.width,
                                     f.size.height - s.size.height);

        tableView.frame = newFrame;
    }
}
呆° 2024-08-30 14:25:35

我不确定我完全理解你所描述的内容,最好有截图。

听起来发生的事情是 UITableView 是屏幕的大小,并且横幅与屏幕底部的 50 像素重叠。所有 UIView 子级都有从其公共 UIView 父级继承的框架、边界和中心属性。

@interface UIView(UIViewGeometry)

// animatable. do not use frame if view is transformed since it will not correctly reflect the actual location of the view. use bounds + center instead.
@property(nonatomic) CGRect            frame;

// use bounds/center and not frame if non-identity transform. if bounds dimension is odd, center may be have fractional part
@property(nonatomic) CGRect            bounds;      // default bounds is zero origin, frame size. animatable
@property(nonatomic) CGPoint           center;      // center is center of frame. animatable
@property(nonatomic) CGAffineTransform transform;   // default is CGAffineTransformIdentity. animatable
// ... from UIView.h

您可以根据需要操纵这些属性,听起来您只需将边界调整为比屏幕小 50 像素,并进行一些数学计算来计算新的中心。

I'm not sure I completely understand what you're describing, it would be nice to have a screenshot.

It sounds like what's happening is the UITableView is the size of the screen and the banner is overlapping the bottom 50 pixels of it. All UIView children have a frame, bounds, and center properties they inherit from their common UIView parent.

@interface UIView(UIViewGeometry)

// animatable. do not use frame if view is transformed since it will not correctly reflect the actual location of the view. use bounds + center instead.
@property(nonatomic) CGRect            frame;

// use bounds/center and not frame if non-identity transform. if bounds dimension is odd, center may be have fractional part
@property(nonatomic) CGRect            bounds;      // default bounds is zero origin, frame size. animatable
@property(nonatomic) CGPoint           center;      // center is center of frame. animatable
@property(nonatomic) CGAffineTransform transform;   // default is CGAffineTransformIdentity. animatable
// ... from UIView.h

You can manipulate these properties as you like, it sounds like you simply need to adjust the bounds to be 50 pixels smaller than the screen, and do some math to calculate your new center.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文