Achieve a Uniform UIBlurEffect in the Primary View of a UISplitView

梦想的初衷 提交于 2019-12-19 04:19:48

问题


I'm using a stock UISplitViewController with out-of-the-box Master and Detail view controllers. In a storyboard, I've added a UIImageView to the Detail controller set to effectively fill the view with a single image.

In the Master controller, I've used the following to blur the background of that controller:

// In viewDidLoad

self.tableView.backgroundColor = [UIColor clearColor];
    UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc]
                                            initWithEffect:blurEffect];
    self.tableView.backgroundView = visualEffectView;
    self.tableView.separatorEffect = [UIVibrancyEffect effectForBlurEffect:blurEffect];

When the Master controller appears above the Detail controller, note how the edges of the Master controller have a dark shadow around the inner edges.

How can these "shadows" be removed to instead render a uniform blur?

More Details

Debugging the view hierarchy in IB reveals a (private?) view called _UIPopoverSlidingChromeView. It has an inset grey frame, and it's definitely what's responsible for the non-uniform blur appearance.

Disabling the blur view altogether and just leaving self.tableview.backgroundColor = [UIColor clearColor] shows _UIPopoverSlidingChromeView's grey frame. It looks like this:

Any thoughts on how to avoid _UIPopoverSlidingChromeView when using UISplitViewController?


回答1:


The problem is that it is a private class that you can't test against.

Fortunately _UIPopoverSlidingChromeView is the subclass of UIPopoverBackgroundView that is public (because in regular popover implementation flow client may customize the popover background chrome by providing a class which subclasses UIPopoverBackgroundView).

for (UIView *subview in self.viewController.view.superview.superview.subviews) {
    if ([subview isKindOfClass:[UIPopoverBackgroundView class]]) {
        subview.alpha = 0.0;
    }
}

This should hide the _UIPopoverSlidingChromeView.




回答2:


    //как убрать дурацкий прямоугольник при прозрачном фоне maser окна в режиме UISplitViewControllerDisplayModeOverlay
    CALayer* v_1 =  self.view.superview.superview.superview.layer.sublayers[0];
    CALayer* v_2=v_1.sublayers[0];
    v_2.borderWidth=0;


来源:https://stackoverflow.com/questions/26164982/achieve-a-uniform-uiblureffect-in-the-primary-view-of-a-uisplitview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!