我可以让一个UIPresentationController在PresentingViewController上有userInteractionEnabled吗?

jol*_*coa 9 ios setuserinteractionenabled ios8 uipresentationcontroller

我正在为iPhone和iPad的通用应用程序构建自定义GUI.在iPad上,它主要依赖于"sideViews"等实用程序,如内容操作,detailInformation等(想想一个高级的SplitView).从视觉的角度来看,新的UIPresentationController让我能够呈现这些"sideViews"(并且不使用dimmedView),并且实现起来非常简单,可以构建和维护,同时仍然可以很好地与故事板集成.但是,当presentViewController可见时,我需要能够操作presentViewController的内容.所以我的问题是,我可以在呈现sideViews时在presentViewController上设置userInteractionEnabled(或类似)吗?

Gle*_*Low 14

UIPresentationController插入其容器视图作为窗口子视图的呈现视图上方,从而外部任何触摸呈现视图由容器视图被困,从不使它的呈现视图.

修复方法是在容器视图上插入一个视图,该视图通过触摸传递到呈现视图.您可以将其用作调光视图或将其backgroundColor设置[UIColor clearColor]为完全透明的视图.在演示控制器代码中设置passthrough视图.

@interface IVPasserView : UIView

@property (strong, nonatomic) NSArray* passthroughViews;

@end

@implementation IVPasserView

- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    UIView* hit = [super hitTest:point withEvent:event];
    if (hit == self)
        for (UIView* passthroughView in _passthroughViews)
        {
            hit = [passthroughView hitTest:[self convertPoint:point toView:passthroughView]
                                 withEvent:event];
            if (hit)
                break;
        }
    return hit;
}

@end
Run Code Online (Sandbox Code Playgroud)

注意:虽然这违反了-[UIView hitTest:withEvent:]它没有返回子视图的精神,但实际上这是系统标准如何UIPopoverPresentationController处理它.如果在passthroughViews那里设置属性,容器视图会hitTest:withEvent:以直通视图响应,即使它们不是superview/subview!因此,它可能会在下一个iOS版本中存活下来.