我希望在我的自定义视图中获得像圆角一样的动作表之类的视觉效果。
containerView = [UIView new];
[containerView setBackgroundColor:[UIColor colorWithWhite:1 alpha:1]];
[self addSubview:containerView];
UIVisualEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *effectView = [[UIVisualEffectView alloc]initWithEffect:blurEffect];
[containerView addSubview:effectView];
我已将子视图添加到容器视图中,我像这样应用了半径。
-(void) addCornerRadius:(float) cornerRad isTopSide:(BOOL) isTopSide
{
cornerRadius = cornerRad;
isTop = isTopSide;
UIBezierPath *maskPath;
UIRectCorner *corner;
if (isTopSide)
{
corner = (UIRectCornerTopLeft|UIRectCornerTopRight);
}
else
{
corner = (UIRectCornerBottomLeft|UIRectCornerBottomRight);
}
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:corner
cornerRadii:CGSizeMake(cornerRad, cornerRad)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.layer.mask = maskLayer;
}
但我在创造效果方面并不像UIAlertController
创造的效果那么近。怎么做到这一点?