【发布时间】:2019-07-20 04:11:00
【问题描述】:
我有一个带有 imageView 的单元格,我想模糊这个图像以便为用户隐藏它。为此,我只是在其上添加了一个模糊视图,但它没有正确调整,并且右侧边缘有一条白色条纹。你知道发生了什么吗?这个问题只出现在物理设备上,在模拟器上就好了。这是我的模糊视图代码。
#import "BlurView.h"
@interface BlurView()
@property (nonatomic, strong) UIVisualEffectView *blurEffectView;
@end
@implementation BlurView
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor clearColor];
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
self.blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
self.blurEffectView.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:self.blurEffectView];
[[self.blurEffectView.widthAnchor constraintEqualToAnchor:self.widthAnchor] setActive:YES];
[[self.blurEffectView.heightAnchor constraintEqualToAnchor:self.heightAnchor] setActive: YES];
[[self.blurEffectView.centerXAnchor constraintEqualToAnchor:self.centerXAnchor] setActive:YES];
[[self.blurEffectView.centerYAnchor constraintEqualToAnchor:self.centerYAnchor] setActive:YES];
}
return self;
}
@end
【问题讨论】:
-
据我所知,您的约束是可以接受的,并且模糊视图看起来像是延伸到视图边缘。您的图像视图是否将图像内容拉伸到边缘?您的图像视图的内容模式设置为什么?
-
显示添加此视图的代码。看起来您没有为
BlurView本身添加约束。 -
看起来在我的代码中我已经打开了
shouldRasterize属性,这是主要问题。当我关闭它时,现在一切看起来都很好。
标签: ios objective-c iphone autolayout