iOS UIVisualEffectView 用在cell上面。滑动时候会存在闪动

底部是一个imageView
UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *effectview = [[UIVisualEffectView alloc] initWithEffect:blur];

使用 imageWithUIView 进行获取图片就不会出现闪动(前提要设置 : imageView.contentMode = UIViewContentModeScaleAspectFill )

// 图片裁剪
            UIImageView *imageView = [UIImageView new];
            imageView.bounds = self.iconBGImageView.bounds;
            imageView.center = CGPointMake(-1000, 0);
            [self addSubview:imageView];
            imageView.image = image;
            imageView.contentMode = UIViewContentModeScaleAspectFill;
            imageView.clipsToBounds = YES;

            UIImage *image2 = [self imageWithUIView:imageView];
            [imageView removeFromSuperview];
            self.iconBGImageView.image = [self changeImage:image];
            self.iconBGImageView.contentMode = UIViewContentModeScaleAspectFill;
            self.iconBGImageView.clipsToBounds = YES;
  • (UIImage) imageWithUIView:(UIView) view{
    // 创建一个bitmap的context
    // 并把它设置成为当前正在使用的context
    UIGraphicsBeginImageContext(view.bounds.size);
    CGContextRef currnetContext = UIGraphicsGetCurrentContext();
    [view.layer renderInContext:currnetContext];
    // 从当前context中创建一个改变大小后的图片
    UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
    // 使当前的context出堆栈
    UIGraphicsEndImageContext();
    return image;
    }

  • (UIImage *)changeImage:(UIImage *)image {
    UIGraphicsBeginImageContext(self.iconBGImageView.size);
    CGRect rect = self.iconBGImageView.bounds;
    [image drawInRect:rect];
    使用下面的就可以
    // [image drawInRect:rect withContentMode:UIViewContentModeScaleAspectFill clipsToBounds:YES];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    // 拉伸不变形
    UIImage *networkImage = [newImage stretchableImageWithLeftCapWidth:newImage.size.width * 0.5
    topCapHeight:0];
    UIGraphicsEndImageContext();
    return newImage;
    }

解决思路: 将图片平铺处理,不能压缩。就可以 UIViewContentModeScaleAspectFill

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。