我正在尝试在UIVisualEffectView上创建透明孔视图。我正在按照here给出的解决方案。我附上了我在here上工作的示例代码。我正在尝试创建一个透明视图,其框架取自模糊视图后面的图像视图。谁能告诉我这里我做错了什么?
答案 0 :(得分:12)
您可以使用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;
});
答案 1 :(得分:0)
针对懒人的解决方案的Swift 5版本:)
while read -r -a line
do
IFS='= ' read -r -a array <<< "$line"
"${array[0]}"+="${array[1]}"
done < file.txt