[英]Search bar in iOS7 half hidden when setting content offset
我在導航控制器中有一個表視圖控制器,在viewDidLoad上我向表視圖頭添加了一些視圖:
//Build up master container view with search bar and another view that has buttons
...
//Set this as the table header
self.tableView.tableHeaderView = masterHeaderContainerView;
如果此時我什么都不做,我的視圖從上到下看起來像
導航欄,搜索欄,帶按鈕的操作欄,表格查看單元格... https://www.dropbox.com/s/mwhipz5qpa9duzw/filterAndActions.PNG
但是,我想隱藏導航欄下的搜索欄,所以我在viewWillAppear中設置了表視圖的內容偏移量
self.tableView.contentOffset = CGPointMake(0, self.searchBar.frame.size.height);
在iOS 6上,這個工作正常,但是在iOS 7上,當我向下滾動以顯示搜索欄時,它已經消失了,它應該是一個空白區域。
可能會給問題提供線索的是,如果我將內容偏移硬編碼為22(搜索欄高度的一半),然后向下滾動,搜索欄就會被看起來像背景的一半隱藏。
https://www.dropbox.com/s/jm1vro769jfhpy8/halfFilterBar.PNG
因此,我設置內容偏移量的數量是覆蓋搜索欄的數量。 任何想法可能會發生在這里?
目標是有一個像Mail應用程序一樣的過濾條,當視圖第一次出現時,它會隱藏在導航欄下面,但可以通過向下滾動來顯示。
我正在以編程方式構建搜索欄和搜索顯示控制器,因為視圖沒有xibs / storyboard,它是標准的UITableViewController子類。
UISearchBar *aSearchBar = [[UISearchBar alloc] initWithFrame:CGRectZero];
UISearchDisplayController *aSearchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:aSearchBar contentsController:self];
aSearchBar.frame = ...
您應該設置為在iOS 7中獲得預期的行為
self.edgesForExtendedLayout = UIRectEdgeNone;
加上這個
[self.view bringSubViewToFront:aSearchBar];
也
[self.tableView setClipsToBounds:YES];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.