2
在導航欄下添加了UISearch欄。 我使用UISearchBar在橫向設備中沒有附加導航欄
[videoSearchBar setFrame:CGRectMake(0, 64, 320, 44)];
爲IOS 7.
當在風景模式有導航欄和搜索欄之間的間隙。 在早期版本中,它無需setFrame即可正確顯示。
在搜索欄下方有一個tableview。
在導航欄下添加了UISearch欄。 我使用UISearchBar在橫向設備中沒有附加導航欄
[videoSearchBar setFrame:CGRectMake(0, 64, 320, 44)];
爲IOS 7.
當在風景模式有導航欄和搜索欄之間的間隙。 在早期版本中,它無需setFrame即可正確顯示。
在搜索欄下方有一個tableview。
導航欄高度在縱向和橫向之間變化。使用topLayoutGuide
來定位您的搜索欄。您可以使用Interface Builder或編程方式執行此操作:
- (void)viewDidLoad
{
[super viewDidLoad];
UISearchBar *searchBar = [[UISearchBar alloc] init];
searchBar.delegate = self;
[self.view addSubview:searchBar];
searchBar.translatesAutoresizingMaskIntoConstraints = NO;
NSDictionary *views = @{@"v":searchBar,
@"topLayoutGuide":self.topLayoutGuide};
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[topLayoutGuide][v]" options:0 metrics:nil views:views]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[v]|" options:0 metrics:nil views:views]];
}
#pragma mark - UISearchBarDelegate
- (UIBarPosition)positionForBar:(id <UIBarPositioning>)bar
{
return UIBarPositionTopAttached;
}
導航欄高度在縱向和橫向之間變化。使用'topLayoutGuide'來定位您的搜索欄。 – albertamg
謝謝@albertamg。你能解釋一下怎麼做。你是指UI構建器還是以編程方式完成。 – Susitha
看到我的答案... – albertamg