问题描述
我正在编写 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.
这就是麻烦所在:每次我使用搜索栏时,显示控制器(我假设)都会使 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 视图.它似乎有一个 touch-up-inside 事件处理程序,在点击时结束搜索.
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.
要将变暗效果限制在细节视图的子视图中,您需要做三件事.(我假设您的 detail-view-controller 是通过 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 到你的细节视图控制器 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) 使搜索区域的包含视图成为这个新视图控制器的视图.为此,请使用 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) 使 UISearchDisplayController 的 searchContentsController 属性引用这个新的视图控制器而不是 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 没有调光?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!