我正在尝试制作简单的 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 模糊效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!