Eli*_*son 10 translucency ios ios8
我正在制作一个自定义控制圈.圆的一部分可以是透明的.如果它是半透明的而不是透明的,它会产生更多的视觉感觉并且看起来更好.
因为视图是矩形的,我只希望圆是半透明的,而不是矩形的其余部分,这是一个问题.
这UIVisualEffectView是自定义控件的背后.

(没有任何在圆圈内呈现的内容用于调试目的)
正如您所看到的,视图模糊了圆圈之外的东西.
我不知道如何仅在视图内部模糊,并且预发布文档几乎是空的.我唯一的想法是创建许多1x1视图来覆盖圆圈,但这似乎不会真正起作用,即使这样做也会是一个缓慢而丑陋的解决方案.如何模糊视图中的内容,而不模糊外部的任何内容?
rob*_*off 30
将圆形视图的图层蒙版设置为实心圆:
CircleControlView *circleView = yourCircleView();
CAShapeLayer *mask = [CAShapeLayer layer];
mask.path = [UIBezierPath bezierPathWithOvalInRect:circleView.bounds].CGPath;
circleView.layer.mask = mask;
Run Code Online (Sandbox Code Playgroud)
斯威夫特操场示例:
import UIKit
import XCPlayground
import QuartzCore
UIGraphicsBeginImageContext(CGSize(width: 100, height: 100))
let viewPath = UIBezierPath(ovalInRect:CGRect(x:1,y:1,width:98,height:98))
viewPath.lineWidth = 2
viewPath.stroke()
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
let view = UIView(frame:CGRect(x:0,y:0,width:100,height:100))
XCPShowView("view", view)
let label = UILabel(frame:view.bounds)
label.text = "This is the text in the background behind the circle."
label.numberOfLines = 0
view.addSubview(label)
let effectView = UIVisualEffectView(effect:UIBlurEffect(style:.ExtraLight))
effectView.frame = view.bounds
view.addSubview(effectView)
let circleView = UIImageView(image:image)
effectView.addSubview(circleView)
let maskPath = UIBezierPath(ovalInRect:circleView.bounds)
let mask = CAShapeLayer()
mask.path = maskPath.CGPath
effectView.layer.mask = mask
Run Code Online (Sandbox Code Playgroud)
结果:

| 归档时间: |
|
| 查看次数: |
3880 次 |
| 最近记录: |