我正在尝试在UIVisualEffectView上创建一种透明的孔 View 。我在给定here的情况下关注解决方案。我已附加了我在here上工作过的示例代码。我正在尝试创建一个透明 View ,其框架是从模糊 View 后面的 ImageView 中获取的。任何人都可以告诉我,我在这里做错了什么?

最佳答案

您可以使用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;
});

关于ios - 在UIVisualEffect View 上创建透明孔,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32292022/

10-08 23:10