在UIVisualEffect视图上创建透明孔

Sid*_*kan 12 objective-c ios uivisualeffectview

我正在尝试在UIVisualEffectView上创建一个透明孔类型的视图.我按照这里给出的解决方案.我附上了我在这里工作的示例代码.我正在尝试创建一个透明视图,其框架取自模糊视图后面的图像视图.谁能告诉我这里我做错了什么?

cno*_*gr8 12

您可以使用a UIBezierPath来创建所需的蒙版.

blurView.layer.mask = ({
    CGRect roundedRect = self.bounds;
    roundedRect.origin.x = roundedRect.size.width / 4.0f;
    roundedRect.origin.y = roundedRect.size.height / 4.0f;
    roundedRect.size.width /= 2.0f;
    roundedRect.size.height /= 2.0f;

    CGFloat cornerRadius = roundedRect.size.height / 2.0f;

    UIBezierPath *path = [UIBezierPath bezierPathWithRect:self.bounds];
    UIBezierPath *croppedPath = [UIBezierPath bezierPathWithRoundedRect:roundedRect cornerRadius:cornerRadius];
    [path appendPath:croppedPath];
    [path setUsesEvenOddFillRule:YES];

    CAShapeLayer *mask = [CAShapeLayer layer];
    mask.path = path.CGPath;
    mask.fillRule = kCAFillRuleEvenOdd;
    mask;
});
Run Code Online (Sandbox Code Playgroud)