我想创建一个左上角和右上角有圆角的UIView。
为了做到这一点,我想用CAShapeLayer掩盖UIView。
这是我正在使用的代码:
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.menuContainerView.bounds
byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
cornerRadii:CGSizeMake(20.0, 20.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.menuContainerView.bounds;
maskLayer.path = maskPath.CGPath;
self.menuContainerView.layer.mask = maskLayer;
但是,当我运行此代码时,看起来掩码没有效果。任何想法为什么不呢?
答案 0 :(得分:0)
我在回答中没有提到的是我还将掩码设置为另一个视图(一个屏幕外)的掩码。显然你不能这样做....我删除了额外的行
self.otherContainerView.layer.mask = maskLayer;
它按预期工作。