0

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.

Community
  • 1
  • 1
Wooseong Kim
  • 1,871
  • 2
  • 21
  • 19

1 Answers1

2

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.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Thank you for your advice. One idea came up to me. make two layers which has exactly same frame. one is `frontView` which contains buttons, another one is `backView` which is half-rounded rect UIView. Then I use code above to make `backView`, and move two buttons to frontView. How about this? – Wooseong Kim Apr 18 '13 at 04:31
  • 1
    Exactly what I was thinking of. Or just move the two buttons out in front, and have them be subviews of `superview.superview` :) – matt Apr 18 '13 at 04:35
  • I solved this problem with two separated views which are subviews of one superView. Your advice is good point. Thank you ;-) – Wooseong Kim Apr 18 '13 at 04:45