gpt4 book ai didi

ios - 如何使用 UIVisualEffectView 模糊图像?

转载 作者:IT老高 更新时间:2023-10-28 12:15:04 27 4
gpt4 key购买 nike

有人可以举一个将模糊应用于图像的小例子吗?我一直在尝试找出代码有一段时间了 :( 在 obj c 还是新的!

The UIVisualEffectView provides a simple abstraction over complex visual effects. Depending on the desired effect, the results may affect content layered behind the view or content added to the view’s contentView.

Apply a UIVisualEffectView to an existing view to apply a blur or vibrancy effect to the exiting view. After you add the UIVisualEffectView to the view hierarchy, add any subviews to the contentView of the UIVisualEffectView. Do not add subviews directly to the UIVisualEffectView itself.

https://developer.apple.com/documentation/uikit/uivisualeffectview#//apple_ref/occ/instp/UIVisualEffectView/contentView

最佳答案

只需将此模糊 View 放在 imageView 上即可。下面是 Objective-C 中的一个例子:

UIVisualEffect *blurEffect;
blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];

UIVisualEffectView *visualEffectView;
visualEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];

visualEffectView.frame = imageView.bounds;
[imageView addSubview:visualEffectView];

和 swift :

var visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .Light))    

visualEffectView.frame = imageView.bounds

imageView.addSubview(visualEffectView)

关于ios - 如何使用 UIVisualEffectView 模糊图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24067719/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com