2

ナビゲーション バーの下に追加された UISearch バー。私が使う

 [videoSearchBar  setFrame:CGRectMake(0, 64, 320, 44)]; 

iOS7用。

ランドスケープ モードの場合、ナビゲーション バーと検索バーの間に隙間があります。以前のバージョンでは、setFrame なしで正しく表示されます。

検索バーの下にテーブルビューがあります。

4

1 に答える 1

5

ナビゲーション バーの高さは、縦向きと横向きの間で変化します。を使用し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;
}
于 2013-10-03T09:59:14.430 に答える