【发布时间】:2016-04-11 03:24:24
【问题描述】:
在我的应用程序中,我通过子类化简单的 UIView 来查看 UIView。但是,如果我尝试使用UIVisualEffectView 做同样的事情,我将无法做到。
这是我使用普通 UIView 可以做的事情:
当我使用 UIVisualEffectView 代替绿色 UIView 时,我看不到透视 UIView ,即使透视 UIView 添加到 UIVisualEffectView 为 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?
【问题讨论】:
-
嗨 Teja,你能实现你在这篇文章中提到的功能吗?如果是这样,您能否帮助我或建议对以下帖子中给出的代码进行一些调整。 *.com/questions/39165751/…
-
@sree_iphonedev 一旦我在电脑前就可以了!
-
你最终解决了吗?
-
不在视觉效果视图上。
标签: ios objective-c uiview uivisualeffectview