Question

I want to make the glow effect spread outside of thisView.

I used this code to make Half-Rounded rect cornered UIVew.

Round two corners in UIView

Here is my code.

+ (UIView *)makeUpperHalfRoundedView:(UIView *)view {
    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    maskLayer.frame = view.bounds;
    UIBezierPath *roundedPath =
    [UIBezierPath bezierPathWithRoundedRect:maskLayer.bounds
                          byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
                                cornerRadii:CGSizeMake(8.f, 8.f)];
    maskLayer.fillColor = [[UIColor blackColor] CGColor];
    maskLayer.backgroundColor = [[UIColor clearColor] CGColor];
    maskLayer.path = [roundedPath CGPath];
//    maskLayer.masksToBounds = NO;

    //Don't add masks to layers already in the hierarchy!
    UIView *superview = [view superview];
    [view removeFromSuperview];
    view.layer.mask = maskLayer;
    [superview addSubview:view];

    return view;
}

And there are two image buttons in this view closed to the boundary. If a touch event happen on buttons, glow effect shows(showsTouchWhenHighlighted)

Before using this piece of code, I just used

thisView.layer.cornerRadius = 8;
thisVIew.layer.masksToBounds = NO;

and glow effect spread outside of 'thisView'.

But after using CAShapeLayer in 'thisView' to masking half-roused rect, the glow effect are masked by boundary.

Was it helpful?

Solution

What you're seeing is exactly how a mask is supposed to work. You are applying the mask to the layer of the superview. Let's call that view superview (just as in your code). Okay, so what will that do? It will mask superview and all its sublayers. That includes its subviews. Its subviews are actually its sublayers.

So, since the buttons are subviews of superview, they are masked like everything else inside superview.

If you don't want that to happen, don't make the buttons subviews of superview. They can sit on top of superview without being its subviews, for example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top