How i detect changes image in a UIImageView in Swift iOS
Asked Answered
T

1

1

I am using UIImageView In my UIViewController. In my case, I want to do if my image view changes then let me know if it was changed or not.

Theodoratheodore answered 14/5, 2021 at 11:28 Comment(2)
Change means image in imageview changes? like you want to detect when image changes.Grisby
How is it going to change? and where do you need to detect that? Can you explain a bit about your goal?Assentation
Z
6

Use KVO.

class ViewController: UIViewController {
    
    @IBOutlet weak var imageView: UIImageView!
    
    private var imageChangeObservation: NSKeyValueObservation?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        imageChangeObservation = imageView.observe(\.image, options: [.new]) { [weak self] (object, change) in
            print("Image changed")
        }
    }
}
Zigrang answered 14/5, 2021 at 12:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.