iOS UI导航栏iPhone中横向模式下的搜索栏高度

iOS UI导航栏iPhone中横向模式下的搜索栏高度,iphone,ios,height,uisearchbar,landscape,Iphone,Ios,Height,Uisearchbar,Landscape,我需要在横向模式下使用搜索栏的帮助。我将其添加到导航栏标题视图中: self.searchBarTop = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 80, 30)]; self.navigationItem.titleView = self.searchBarTop; 在横向模式下,要适当适应,其尺寸太大: 有什么建议吗?使用以下代码查找iphone的方向,然后相应地设置搜索栏的框架。在ViewDidLoad中设置搜索栏纵向模式的

我需要在横向模式下使用搜索栏的帮助。我将其添加到导航栏标题视图中:

self.searchBarTop = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 80, 30)];
self.navigationItem.titleView = self.searchBarTop;
在横向模式下,要适当适应,其尺寸太大:


有什么建议吗?

使用以下代码查找iphone的方向,然后相应地设置搜索栏的框架。在ViewDidLoad中设置搜索栏纵向模式的框架

- (void)viewDidLoad {
    [super viewDidLoad];
    UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(-5.0, 0.0, 320.0, 44.0)];
    UIView *searchBarView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 310.0, 44.0)];
    searchBar.delegate = self;
    [searchBarView addSubview:searchBar];
    self.navigationItem.titleView = searchBarView;
}

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration {
    if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {     

        UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(-5.0, 0.0, 320.0, 44.0)];
        UIView *searchBarView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 310.0, 44.0)];
        searchBar.delegate = self;
        [searchBarView addSubview:searchBar];
        self.navigationItem.titleView = searchBarView;
    }
    else
    {
        UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(-5.0, 0.0, 480.0, 44.0)];
        UIView *searchBarView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 470.0, 44.0)];
         searchBar.delegate = self;
        [searchBarView addSubview:searchBar];
        self.navigationItem.titleView = searchBarView;

    }
}

这肯定会对您有所帮助。

使用以下代码查找iphone的方向,然后相应地设置搜索栏的边框。在ViewDidLoad中设置搜索栏纵向模式的边框

- (void)viewDidLoad {
    [super viewDidLoad];
    UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(-5.0, 0.0, 320.0, 44.0)];
    UIView *searchBarView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 310.0, 44.0)];
    searchBar.delegate = self;
    [searchBarView addSubview:searchBar];
    self.navigationItem.titleView = searchBarView;
}

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration {
    if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {     

        UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(-5.0, 0.0, 320.0, 44.0)];
        UIView *searchBarView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 310.0, 44.0)];
        searchBar.delegate = self;
        [searchBarView addSubview:searchBar];
        self.navigationItem.titleView = searchBarView;
    }
    else
    {
        UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(-5.0, 0.0, 480.0, 44.0)];
        UIView *searchBarView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 470.0, 44.0)];
         searchBar.delegate = self;
        [searchBarView addSubview:searchBar];
        self.navigationItem.titleView = searchBarView;

    }
}

这肯定会对您有所帮助。

显然,这是定制UI搜索栏的灰色区域。我已经设法使用另一种方法将搜索栏移动到导航栏之外。

显然,这是灰色区域自定义UISearchBar。我设法用另一种方法将搜索栏移到导航栏之外。

不幸的是,这没有帮助。您始终将高度设置为44点。但横向模式下的navigationController的高度为32点。像这样,我需要搜索栏的高度为30点或小于1点的上/下边距。在代码行UIView*searchBarView=[[UIView alloc]initWithFrame:CGRectMake0.0,0.0,470.0,44.0]的if-else部分更改搜索栏的高度;不,这也没用。显然,搜索栏的高度无法更改…不幸的是,这没有帮助。您始终将高度设置为44点。但横向模式下的navigationController的高度为32点。像这样,我需要搜索栏的高度为30点或小于1点的上/下边距。在代码行UIView*searchBarView=[[UIView alloc]initWithFrame:CGRectMake0.0,0.0,470.0,44.0]的if-else部分更改搜索栏的高度;不,这也没用。显然,搜索栏的高度无法更改。。。