创建模糊覆盖视图在新iOS的音乐应用程序中,我们可以看到相册封面背后的一个视图模糊了它。这样的事情怎么能实现呢?我看过文件,但没有发现任何东西。
3 回答
大话西游666
TA贡献1817条经验 获得超14个赞
- (UIView *)applyBlurToView:(UIView *)view withEffectStyle:(UIBlurEffectStyle)style andConstraints:(BOOL)addConstraints{ //only apply the blur if the user hasn't disabled transparency effects if(!UIAccessibilityIsReduceTransparencyEnabled()) { UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:style]; UIVisualEffectView *blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect]; blurEffectView.frame = view.bounds; [view addSubview:blurEffectView]; if(addConstraints) { //add auto layout constraints so that the blur fills the screen upon rotating device [blurEffectView setTranslatesAutoresizingMaskIntoConstraints:NO]; [view addConstraint:[NSLayoutConstraint constraintWithItem:blurEffectView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:view attribute:NSLayoutAttributeTop multiplier:1 constant:0]]; [view addConstraint:[NSLayoutConstraint constraintWithItem:blurEffectView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:view attribute:NSLayoutAttributeBottom multiplier:1 constant:0]]; [view addConstraint:[NSLayoutConstraint constraintWithItem:blurEffectView attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:view attribute:NSLayoutAttributeLeading multiplier:1 constant:0]]; [view addConstraint:[NSLayoutConstraint constraintWithItem:blurEffectView attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:view attribute:NSLayoutAttributeTrailing multiplier:1 constant:0]]; } } else { view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7]; } return view;}
- 3 回答
- 0 关注
- 655 浏览
添加回答
举报
0/150
提交
取消