当前位置: 首页 > 工具软件 > UIView-Blur > 使用案例 >

maskview ios android,ios – 如何(成功)将maskView设置为UIView?

毕泽宇
2023-12-01

我正在制作一个基于相机的应用程序,并希望在相机预览上制作一个磨砂覆盖图,从磨砂视图中切出一个圆角矩形.

我一直在努力用UIView的maskLayer实现这一点,在iOS 8中引入并且已经非常不成功.

这是我的代码目前的样子:

// Blur the preview

UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];

UIView *blurView = [[UIVisualEffectView alloc] initWithEffect:effect];

blurView.translatesAutoresizingMaskIntoConstraints = NO;

[self.view insertSubview:blurView aboveSubview:imagePicker.view];

// Make blur view fill screen

{

[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[blurView]-0-|"

options:0

metrics:nil

views:NSDictionaryOfVariableBindings(blurView)]];

[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[blurView]-0-|"

options:0

metrics:nil

views:NSDictionaryOfVariableBindings(blurView)]];

}

// Add a rounded of transparency to the blurView **not working**

UIView *mask = [[UIView alloc] initWithFrame:CGRectMake(50.f, 50.f, 50.f, 50.f)];

mask.alpha = 1.0f;

mask.backgroundColor = [UIColor redColor];

[blurView setMaskView:mask]; // Remove this line, and everything is frosted. Keeping this line and nothing is frosted.

正如我的评论所示,添加蒙版可以完全去除磨砂视图(更改蒙版的不透明度不起作用).我知道这不会产生我正在寻找的效果(它应该只在那个矩形中磨砂),但我不能让maskView以任何容量工作.

 类似资料: