底部是一个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
网友评论