UISearchDisplayController没有调光? [英] UISearchDisplayController Without Dimming?

查看:77
本文介绍了UISearchDisplayController没有调光?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个SplitView iPad应用程序。在DetailViewController中,有一个包含 UITableView UISearchBar 及其控制器的视图。此视图不代表为DetailViewController保留的整个屏幕空间。实际上,它只使用了一半。另一半有一个 UIImageView

I am writing a SplitView iPad app. Inside the DetailViewController, there's a little view that contains a UITableView and a UISearchBar and its controller. This view does not represent the whole screen space reserved for the DetailViewController. Actually, it uses just half of it. There's an UIImageView on the other half.

这就是麻烦的来源:每次我使用搜索bar,displaycontroller(我假设)调暗DetailViewController中的所有内容,包括图像视图。这与人们在运行应用程序时的期望不一致。有没有办法将框架设置为暗灰色?或者至少禁用调光好吗?

And this is where trouble comes in: every time I use the search bar, the displaycontroller (I assume) dims everything present inside the DetailViewController, including the image view. That is not consistent with what someone would expect when running the app. Is there any way to set the frame to be dimmed? Or at least disable dimming for good?

提前致谢。

推荐答案

你是正确的,正是UISearchDisplayController正在管理你所看到的调光效果。

You are correct that it is the UISearchDisplayController that is managing the "dimming" effect that you're seeing.

UISearchDisplayController正在做的是将一个UIControl作为子视图添加到searchContentsController(UISearchDisplayController的一个属性)的视图中,这可能是你的详细视图控制器。这个UIControl只是一个灰色背景的alpha'd视图。它似乎有一个触摸式内部事件处理程序,在点击时结束搜索。

What the UISearchDisplayController is doing is adding a UIControl as a subview to the view of the searchContentsController (a property of UISearchDisplayController), which is likely your detail-view controller. This UIControl is just an alpha'd view with a gray background. It seems to have a touch-up-inside event handler that ends searching when tapped.

要将调光效果限制在细节视图的子视图中,需要做三件事。 (我假设您的详细视图控制器是通过xib定义的。如果没有,这些步骤也可以在代码中完成。)

To constrain the dimming effect to your sub-view of the detail-view, you need to do three things. (I'm assuming your detail-view-controller is defined via a xib. If not, these steps can be done in code too.)

1)添加一个新的UIViewController到你的detail-view-controller xib。将此新视图控制器附加到详细视图控制器的IBOutlet。在我的例子中,我称之为_searchAreaViewController。这很重要,即使你不会访问视图控制器(但请记住,你必须在某个时候释放它)

1) add a new UIViewController to your detail-view-controller xib. Attach this new view-controller to an IBOutlet of your detail-view-controller. In my example I call this "_searchAreaViewController". This is important, even if you wont ever access the view controller (but remember, you'll have to release it at some point)

@interface DetailViewController : UIViewController <UIPopoverControllerDelegate, UISplitViewControllerDelegate, UITableViewDelegate, UITableViewDataSource> {

    UIPopoverController *popoverController;
    UIToolbar *toolbar;

    id detailItem;
    UILabel *detailDescriptionLabel;

    IBOutlet UIViewController* _searchAreaViewController;
}

2)使搜索区域的包含视图成为这个新视图的视图-controller。要执行此操作,请使用Interface Builder通过将插座拖动到searchAreaViewController并选择视图插座来为此视图设置新的参考插座。你必须有一个包含视图 - 它应该是你的详细视图的子视图,它应该包含UISearchBar,可能包含你的UITableView。

2) make the containing view for your search area the view of this new view-controller. To do this, use Interface Builder to set a new referencing outlet for this view by dragging the outlet to the searchAreaViewController and selecting the "view" outlet. You must have a containing view - it should be a subview of your detail-view, and it should contain the UISearchBar and likely your UITableView.

3)制作searchContentsController属性UISearchDisplayController的引用是指这个新的视图控制器而不是detail-view-controller。这只能通过Interface Builder来完成,因为属性是只读的(IB有一些神奇的功能可以使它工作吗?)如果你需要通过代码执行这一步,你必须继承UISearchDisplayController并从中返回正确的值。属性覆盖searchContentsController。

3) make the searchContentsController property of the UISearchDisplayController refer to this new view controller instead of the detail-view-controller. This can only be done via Interface Builder as the property is read-only (IB has some magic to make this work?) If you need to do this step via code you'll have to subclass the UISearchDisplayController and return the correct value from a property override of "searchContentsController".

我做了一个示例应用来演示这个,我必须添加到SplitView模板的唯一代码行是步骤中列出的代码1以上。其他一切只是添加视图/控制器并在IB中正确连接它们。

I made a sample app to demonstrate this and the only line of code I had to add to the SplitView template was the one listed in step 1 above. Everything else was just adding the views/controllers and connecting them properly in IB.

祝你好运!

这篇关于UISearchDisplayController没有调光?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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