当前位置:  开发笔记 > 编程语言 > 正文

如何在UIVisualEffectView上进行透明剪切?

如何解决《如何在UIVisualEffectView上进行透明剪切?》经验,为你挑选了0个好方法。

在我的应用程序中,我通过UIView继承简单的UIView 来进行透视.但是,如果我尝试使用相同的UIVisualEffectView,我无法做到.

以下是我使用普通能够做到的事情UIView:

在此输入图像描述

当我使用UIVisualEffectView代替绿色时UIView,我看不到通过UIView看到,即使看到通过UIView添加到UIVisualEffectViewas subview.

在此输入图像描述

码:

- (void)drawRect:(CGRect)rect { //this is same for the UIVIew and for the UIVisualEffectView
    [super drawRect:rect];

    CGContextRef context = UIGraphicsGetCurrentContext();
    // Clear any existing drawing on this view
    // Remove this if the hole never changes on redraws of the UIView
    CGContextClearRect(context, self.bounds);

    // Create a path around the entire view
    UIBezierPath *clipPath = [UIBezierPath bezierPathWithRect:self.bounds];

    // Your transparent window. This is for reference, but set this either as a property of the class or some other way
    CGRect transparentFrame;
    // Add the transparent window
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:transparentFrame cornerRadius:5.0f];
    [clipPath appendPath:path];

    // NOTE: If you want to add more holes, simply create another UIBezierPath and call [clipPath appendPath:anotherPath];

    // This sets the algorithm used to determine what gets filled and what doesn't
    clipPath.usesEvenOddFillRule = YES;
    // Add the clipping to the graphics context
    [clipPath addClip];

    // set your color
    UIColor *tintColor = [UIColor greenColor]; 

    // (optional) set transparency alpha
    CGContextSetAlpha(context, 0.7f);
    // tell the color to be a fill color
    [tintColor setFill];
    // fill the path
    [clipPath fill];
}

问题:为什么这不起作用UIVisualEffectView

推荐阅读
李桂平2402851397
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有