不知道爲什麼,我的iOS 7搜索欄留下了一個合適的空間。在iOS 6中沒關係。iOS 7 UISearchBar右間距
我知道它與段索引有關,因爲如果我刪除它,空間消失,但我不知道如何解決它。有什麼想法嗎?
不知道爲什麼,我的iOS 7搜索欄留下了一個合適的空間。在iOS 6中沒關係。iOS 7 UISearchBar右間距
我知道它與段索引有關,因爲如果我刪除它,空間消失,但我不知道如何解決它。有什麼想法嗎?
創建UISearchBar
,直到出現一個更好的答案,我只是手動更改搜索欄這樣的框架:
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
CGRect barFrame = self.searchBar.frame;
barFrame.size.width = self.view.bounds.size.width;
self.searchBar.frame = barFrame;
}
我也是在我的應用程序連接一個UISearcBar
,並沒有什麼不對,甚至有我的應用程序支持旋轉也。
你能嘗試刪除並重新在storyboard/xib
同樣的事情發生。您是否像我一樣在表視圖右側有段索引? – Odrakir
不,我不。嘗試在'autolayout'中設置'SearchBar''width constraints'。 –
因爲表視圖始終葉15px右側的索引視圖部分,因此您應該在重新加載表格視圖後調整大小的海德吧
第一張:
self.tblData.sectionIndexBackgroundColor = [UIColor clearColor]; //(iOS >= 7 only)
作弊時間:
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
[self performSelector:@selector(resizeSearchBar) withObject:nil afterDelay:0.01];
}
- (void) resizeSearchBar
{
CGRect frame = self.searchBar.frame;
if (frame.size.width < self.tblData.frame.size.width) {
frame.size.width = self.tblData.frame.size.width;
}
self.searchBar.frame = frame;
}
- (void) reloadTableData // call it anytime you want to reload table view
{
[self.tblData reloadData];
[self performSelector:@selector(resizeSearchBar) withObject:nil afterDelay:0.01];
}
推薦 不要騙我一樣,只是做了簡單的方法:
self.searchBar.searchBarStyle = UISearchBarStyleMinimal; // iOS >= 7 only
嵌入您在一個UIView,然後添加的UISearchBar作爲tableHeaderView。在故事板中以這種方式構建它爲我工作。我猜iOS調整了tableHeaderView中的UISearchBar,但留下了一個基本的UIView(並且不費心去查看它)。
您可能還需要使部分指標透明,我做到了與:
[[UITableView appearance] setSectionIndexBackgroundColor:[UIColor clearColor]];
[[UITableView appearance] setSectionIndexTrackingBackgroundColor:[UIColor clearColor]];
完美編輯:此代碼僅適用於iOS 7 – user2159978
我添加爲頂級視圖,而不是表視圖的一個子視圖搜索欄。使用自動佈局將搜索欄固定到頂部指南,並在搜索欄和表格視圖之間使用垂直空間約束0。
添加搜索欄裏面一個UIView把儘可能的tableView的頭視圖。將桌面視圖的sectionIndexBackgroundColor
設置爲清除顏色,因爲它覆蓋標題。
使用iOS 7,7.1測試;
方法viewDidLayoutSubviews
接受的解決方案使屏幕閃爍。 相反,我所做的就是創建UISearchBar
一個子類,僅僅做到這一點:
FullWidthSearchBar.h:
@interface FullWidthSearchBar : UISearchBar
@end
FullWidthSearchBar。L:
#import "FullWidthSearchBar.h"
@implementation FullWidthSearchBar
- (void)setFrame:(CGRect)frame {
frame.size.width = self.superview.bounds.size.width;
[super setFrame:frame];
}
@end
然後我分配一個類來對我的廈門國際銀行在搜索欄:
我使用SearchDisplayController時有同樣的問題與iPhone 6/6Plus。 (使用Swift)
我試圖設置搜索欄的框架,但沒有運氣,但我注意到,如果我點擊UISearchBar的textField,然後取消它,那麼它會採取適當的視圖大小。因此,我設法通過使用搜索在viewController的ViewDidLoad中調用以下代碼來解決該問題。
self.searchController.setActive(true, animated: false)
self.searchController.setActive(false, animated: false)
問題是正確的白色塊,所以如果我們改變塊顏色一樣的搜索欄背景,它看起來很正常。
只是
if (IOS7) {
self.tableview.backgroundColor = [UIColor colorWithPatternImage:self.searchBar.backgroundImage];
}
self.contactsTableView.sectionIndexBackgroundColor = [UIColor clearColor];
的原因在於白邊是因爲索引層有一個白色背景,並在搜索欄的頂部。這應該足夠了。
是第一個tableviewcell的Searchbar子視圖嗎? –
不,是UITableView – Odrakir
的子視圖,請向我展示您將searchbar添加爲tableview的子視圖的代碼! –