如果 UIImageView 是我的类(class),我会通过以下方式解决这个问题:
class myUIImageView{
var image : UIImage? {
didSet {
if self.image != nil{
//do my stuff
}
}
}
//Other fields and functions
}
What I want is to be notified (Observer Like)
最佳答案
我确实找到了答案...Swift 允许覆盖 var
所以这里没有真正的复杂性。只需将使用 UIImageView
的位置更改为使用 myUIImageView
即可。
class myUIImageView : UIImageView{
override var image: UIImage?{
didSet {
if image != nil{
//do your stuff (add effects, layers, ...)
} else {
//clean your filter or added layer (remove your effects over the view)
}
}
}
}
更新
Be advice, if your UIImageView is part of a Collection View you should remove the effect when the collection reuses your view. Otherwise it will remain visible even if no image is being shown.
关于ios - 如果已设置 UIImageView 图像,有一种方法可以快速通知吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30060180/