[英]Add blur mask on top and bottom of the screen in Objective-C
if (!UIAccessibilityIsReduceTransparencyEnabled()) {
self.BlurView.backgroundColor = [UIColor clearColor];
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
blurEffectView.frame = self.view.bounds;
[blurEffectView setAlpha:1.0];
[self.BlurView addSubview:blurEffectView];
}
self.BlurView
是UIView
类型。
您可以保留上部和底部视图。 并且可以根据您的上下尺寸调整框架blurEffectView.frame
。
希望这会帮助你。
在顶部添加UIVisualEffectView:
UIVisualEffectView * vs = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]]; vs.frame = self.view.bounds; [self.view addSubview:vs];
添加此代码:
CAGradientLayer * layer = [CAGradientLayer layer]; layer.frame = tableHolder.bounds; layer.colors = [NSArray arrayWithObjects:(id)[UIColor blackColor].CGColor, (id)[UIColor clearColor].CGColor, (id)[UIColor clearColor].CGColor, nil]; layer.locations = @[@0.90,@0.99,@1.0]; layer.startPoint = CGPointMake(0.0, 1.0f); layer.endPoint = CGPointMake(0.0f, 0.0f); tableHolder.layer.mask = layer; tableHolder.layer.masksToBounds = true; [tableHolder.layer insertSublayer:layer atIndex:0];
根据自己的需要调整变量,您必须更改位置。
你不是“模糊”顶部和底部,而是通过渐变层逐渐掩盖它们。
我能想出一种实现这种效果的方法。 但你需要的不是模糊面具,你需要使用剪贴蒙版。
1-提供一个模态视图控制器,其视图在后面包含一个UIVisualEffectView,前面的scrollview / tableview / collection视图从顶部和底部偏移40px(或者你想要的多少)。 2-使用为任务定制的黑白图像向滚动视图添加遮罩,您可以使用以下代码添加遮罩:
var maskImage = UIImage(name: "yourMask")
var maskLayer = CALayer()
maskLayer.frame = scrollView.bounds()
maskLayer.contents = maskImage.CGImage
scrollview.layer.mask = maskLayer
3-或者,您也可以使用CAGradientLayer来实现相同的效果(这也适用于缩放)。 关于如何创建渐变层的堆栈溢出有很多解决方案,如下所示: 在iOS中以编程方式创建渐变图像
话虽如此,我不明白为什么你的问题被投了票。 我认为这是一个非常好的问题。
希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.