图片视频毛玻璃效果实现

Posted 宁静暖风

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了图片视频毛玻璃效果实现相关的知识,希望对你有一定的参考价值。

毛玻璃效果主要实现就是在图片(imageview)上加一个 UIVisualEffectView

@property (nonatomic, strong) UIVisualEffectView *effectView;// 毛玻璃处理模糊图片
#import "VideoTableViewCell.h"
#import "UIImageView+WebCache.h"

@interface VideoTableViewCell()
@property (nonatomic, strong) UIImageView *vadioImageView; // 模糊图片
@property (nonatomic, strong) UIVisualEffectView *effectView;// 毛玻璃处理模糊图片
@property (nonatomic, strong) UIImageView *backgroundIV;

@end

@implementation VideoTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.separatorInset = UIEdgeInsetsZero;
        
        [self.contentView addSubview:self.vadioImageView];// 模糊图片
        [self.contentView addSubview:self.effectView];// 毛玻璃处理模糊图片
        [self.contentView addSubview:self.backgroundIV]; // 清晰图片
        
        __weak typeof(self)weakself = self;
        [self.backgroundIV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakself.mas_top).offset(10 / WIDTH_6S_SCALE);
            make.left.right.equalTo(weakself);
            make.height.mas_offset(IMG_HEIGHT / WIDTH_6S_SCALE);
        }];
        [self.vadioImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakself.mas_top).offset(10 / WIDTH_6S_SCALE);
            make.left.right.equalTo(weakself);
            make.height.mas_offset(IMG_HEIGHT / WIDTH_6S_SCALE);
        }];
        [self.effectView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakself.mas_top).offset(10 / WIDTH_6S_SCALE);
            make.left.right.equalTo(weakself);
            make.height.mas_offset(IMG_HEIGHT / WIDTH_6S_SCALE);
        }];
        
        [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakself.backgroundIV.mas_top).offset(-10 / HEIGHT_6S_SCALE);
            make.left.right.equalTo(weakself);
            make.bottom.equalTo(weakself.backgroundIV.mas_bottom).offset(10 / HEIGHT_6S_SCALE);
        }];
    }
    return self;
}
#pragma mark - set
- (void)setHomePageModelList:(HomePageModelList *)homePageModelList
{
    _homePageModelList = homePageModelList;
    NSURL *videoUrl = [NSURL URLWithStringAddOffset:self.homePageModelList.file];
    WS(ws);
    [UIImage getImageFromVideoURLString:videoUrl.absoluteString handle:^(NSDictionary *dic) {
        ws.backgroundIV.image = dic[@"image"];
        ws.vadioImageView.image = dic[@"image"];
    }];
}
#pragma mark - init
- (UIImageView *)backgroundIV
{
    if (!_backgroundIV) {
        _backgroundIV = [[UIImageView alloc]init];
        _backgroundIV.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _backgroundIV;
}
- (UIImageView *)vadioImageView
{
    if (!_vadioImageView)
    {
        _vadioImageView = [[UIImageView alloc]init];
        _vadioImageView.backgroundColor = [UIColor grayColor];
        _vadioImageView.image = [UIImage imageNamed:@"h4"];
        //        _vadioImageView.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _vadioImageView;
}

- (UIVisualEffectView *)effectView
{
    if (!_effectView)
    {
        _effectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
        _effectView.alpha = 0.9f;
    }
    return _effectView;
}
@end

 

以上是关于图片视频毛玻璃效果实现的主要内容,如果未能解决你的问题,请参考以下文章

iOS 实现简单的毛玻璃效果

CSS代码片段

CSS代码片段

CSS3实现毛玻璃(图片模糊)效果

opencv:运用cv2给视频加水印

CSS实现背景图片模糊——毛玻璃效果 | 浅谈CSS属性 filterbackdrop-filter