0

Im trying to create a class that adds blur effect to images passed into it when initialized but am getting an error to pass in the image view. I'm using Xcode 7.3, Swift 2.2; here is my code, please take a look.

This is my class

class addBlurEffect: UIViewController {

private var newBlurEffect = UIVisualEffectView(effect: UIBlurEffect(style: .Light))
private var objectToBlur = UIImageView()

convenience init(objToBlur: AnyObject) {
    self.init()

    objectToBlur = objToBlur as! UIImageView
    blur()
}

func blur() {
    newBlurEffect.frame = objectToBlur.bounds
    objectToBlur.addSubview(newBlurEffect)
}

}

This is my code in the ViewController.swift file

@IBOutlet weak var blurHeader: UIImageView!

var addBlur = addBlurEffect(_: blurHeader)

But I get this error "Instance member 'blurHeader' cannot be used on type 'ViewController'" instance error

Any help is greatly appreciated in pointing me to a possible solution. Thanks.

Oh, I also tried the following with the same results:

convenience init(objToBlur: UIImageView) {
    self.init()

    objectToBlur = objToBlur
    blur()
}
4

1 回答 1

1

There are two problems with this:

@IBOutlet weak var blurHeader: UIImageView!
var addBlur = addBlurEffect(_: blurHeader)

First, the second line is not even Swift. It's just nonsense. Perhaps you mean:

@IBOutlet weak var blurHeader: UIImageView!
var addBlur = addBlurEffect(objToBlur:blurHeader)

But you won't be able to say that either, at least not the way you've shown it, because you cannot initialize a property (addBlur) with reference to another property (blurHeader).

于 2016-03-24T13:11:15.717 回答