[英]Extra space above search bar when UISearchDisplayController is active
I have a popover with a UITableViewController
as the content view controller. 我有一个带有
UITableViewController
作为内容视图控制器。 The table view has a UISearchBar
as its header view. 表视图有一个
UISearchBar
作为其标题视图。
Now, on iOS 6 everything looks good when the UISearchDisplayController
becomes active. 现在,在iOS 6上,当
UISearchDisplayController
变为活动状态时,一切看起来都很好。 But, on iOS 7 there will be an extra space above the search bar. 但是,在iOS 7上,搜索栏上方会有一个额外的空间。
So how can I get rid of this extra space above the search bar on iOS 7? 那么如何摆脱iOS 7搜索栏上方的这个额外空间呢?
The solution is to set the property edgesForExtendedLayout
of the UITableViewController
to UIRectEdgeNone
. 解决方案是将
UITableViewController
的属性edgesForExtendedLayout
设置为UIRectEdgeNone
。
- (void)viewDidLoad {
[super viewDidLoad];
if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) { /// iOS 7 or above
self.edgesForExtendedLayout = UIRectEdgeNone;
}
}
This property has the value UIRectEdgeAll
by default . 默认情况下,此属性的值为
UIRectEdgeAll
。 Which means all edges of the view will be extended to keep an extra space for the status bar (the height of the space above the search bar is exactly 20px, the same height of the status bar). 这意味着视图的所有边缘都将被扩展,以便为状态栏保留额外的空间(搜索栏上方空间的高度恰好为20px,与状态栏的高度相同)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.