winsmith
winsmith

Reputation: 21572

iOS: How do I notice when a view is behind a popover?

In my application, I'm showing a popover, which causes all tinted UIImageViews behind the popover to desaturate. I want this behaviour also for UILabels and custom UIView subclasses on the screen. To achieve that, I need to observe when a popover opens, and when it closes, so I can update my colors manually.

My first approach was to observe the UIView's tintColor or tintAdjustmentMode properties. Like this:

override var tintAdjustmentMode: UIViewTintAdjustmentMode {
    didSet {
        // This does not get called
    }
}

However, these don't seem to get called, even though self.tintAdjustmentMode equals true when I check manually while a popover is shown.

Another approach would be to manually call a helper method from the ViewController that presents the popover (in this case a CollectionViewController). The problem with that is that this does not work when another ViewController (say the enclosing Navigation Controller) presents a popover. So that's not really what I want either.

What are other approaches that allow me to react to a popover being displayed over a view's current view controller?

Upvotes: 1

Views: 290

Answers (1)

winsmith
winsmith

Reputation: 21572

To answer my own question, there is a UIView method tintColorDidChange to overwrite.

override func tintColorDidChange() {
    // This gets called
}

Apple Reference: https://developer.apple.com/reference/uikit/uiview/1622620-tintcolordidchange

Upvotes: 2

Related Questions