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


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)