我应该如何使用UISplitView自适应用户界面呈现UISearchController? [英] How should I present a UISearchController using a UISplitView adaptive user interface?

查看:169
本文介绍了我应该如何使用UISplitView自适应用户界面呈现UISearchController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用具有自适应 UISplitViewController 用户界面的通用故事板。

Using a universal storyboard with an adaptive UISplitViewController user interface.

我想提供一个搜索控制器主(主)方面,使用以下代码(来自主视图控制器):

I want to present a search controller on the primary (master) side, using the following code (from the master view controller):

static NSString * const kCGISearchViewControllerID = @"SearchViewControllerID";

- (IBAction)searchButtonClicked:(UIBarButtonItem *)__unused sender {
    SearchViewController *searchResultsController = [self.storyboard instantiateViewControllerWithIdentifier:kCGISearchViewControllerID];
    self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController];
    self.searchController.searchResultsUpdater = searchResultsController;
    self.searchController.hidesNavigationBarDuringPresentation = NO;
    [self presentViewController:self.searchController animated:YES completion:nil];
}

它最初似乎正常工作(无论起始方向):

It initially appears to work correctly (regardless of the starting orientation):

自动旋转后出现问题(键盘仍然可见,底层内容仍然变暗,但搜索栏已消失):

Problems show up after autorotation (keyboard still visible, underlying content still dimmed, but the search bar has disappeared):

旋转回横向时,搜索bar重新出现,但其宽度现在错误:

Upon rotating back to landscape, the search bar reappears, but its width is now wrong:

(我也尝试在<$ c $中放置搜索控制器的 searchBar c> titleView 。当searchBar正确适应时,搜索结果控制器仍然看起来不正确。)

(I've also tried placing the search controller's searchBar in the titleView. While the searchBar adapts correctly, the search results controller still doesn't look right.)

我错过了什么向anima提供 UISearchController 当UI适应不断变化的尺寸等级时,它本身是正确的吗?

What am I missing to get a presented UISearchController to animate itself properly as the UI adapts to changing size classes?

更新:

添加 self.definesPresentationContext = YES; 使搜索栏/结果显示在主视图中,但搜索栏在导航下为设置动画吧,并且不可见。另一个问题是,当它从肖像(具有状态栏)旋转回到横向时,搜索栏高度不会缩小。

Adding self.definesPresentationContext = YES; gets the search bar/results to appear within the primary view, but the search bar is animating under that navigation bar, and isn't visible. The other issue is that the search bar height doesn't shrink, when it rotates from portrait (which has a status bar), back to landscape.

推荐答案

您使用的是什么Xcode版本?什么iOS版本在模拟器上?

尝试使用Xcode 6,iOS 8.4 - 这是我在MasterVC中使用的所有代码:

What Xcode version are you using? What iOS version on the simulator?
Tried that using Xcode 6, iOS 8.4 - That's all the code I used in the MasterVC:

class MasterViewController: UITableViewController {

    @IBAction func search(sender: UIBarButtonItem) {
        let searchController = UISearchController(searchResultsController: nil)
        searchController.hidesNavigationBarDuringPresentation = false
        presentViewController(searchController, animated: true, completion: nil)
    }
...
}

它出现在Master中并锁定屏幕的方向!自您发布答案后,行为可能已发生变化。

It's presented within the Master and locks the orientation of the screen! The behavior might have changed since you posted your answer.

这篇关于我应该如何使用UISplitView自适应用户界面呈现UISearchController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆