iOS blur effect to ImageView with Swift(使用 Swift 对 ImageView 的 iOS 模糊效果)
问题描述
我正在尝试制作简单的 iOS 应用程序.我需要制作具有模糊效果的图像视图.我在 Stack Overflow 上找到了这段代码:
I am trying to make simple iOS app. I need to make image view with blur effect. I found this code on Stack Overflow:
class BlurImageView: UIImageView {
override func awakeFromNib() {
super.awakeFromNib()
}
required init(coder aDecoder: NSCoder!){
super.init(coder: aDecoder)
var blur:UIBlurEffect = UIBlurEffect(style: UIBlurEffectStyle.Light)
var effectView:UIVisualEffectView = UIVisualEffectView (effect: blur)
effectView.frame = frame
addSubview(effectView)
}
}
我需要将这个类连接到我的 image_view,但我不知道该怎么做.我尝试在 ViewController 的 view_did_load 函数中执行此操作(image_view 是一个出口)
And I need to connect this class to my image_view, but I don't know how to do it.
I try to do it in my view_did_load function in my ViewController (image_view is a outlet)
override func viewDidLoad() {
super.viewDidLoad()
image_view = BlurImageView()
}
但是 NSCoder 是必需的……它是什么?也许我的方式是错误的方式?
but NSCoder required... What is it? maybe my way is a wrong way?
推荐答案
你需要让你的 image_view 成为 BlurImageView 的一个实例,所以在你的视图控制器和你的image_view 是一个 outlet,你需要让它成为 BlurImageView 的实例,而不是 UIImageView 的实例.
You need to make your image_view an instance of BlurImageView, so in your view controller and where your image_view is an outlet, you need to make it an instance of BlurImageView and not an instance of an UIImageView.
这篇关于使用 Swift 对 ImageView 的 iOS 模糊效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 Swift 对 ImageView 的 iOS 模糊效果
基础教程推荐
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
