I have a custom UIView
that with a timer displays the current time, which is set inside a UITableViewCell
. Is there a way to detect that user is no longer viewing this custom UIView
I have (say by navigating to a different tab)? I would like to stop this timer when my UIView
is no longer visible on screen. I am using Swift.
I see there is a method I can override called didMoveToWindow
, which seem to be triggered when I change tabs, but I'm not very experienced with iOS and what methods or properties to look for to tell if the view is actually visible to the user or not on screen.
I need some kind of method that are called, similar to viewDidAppear
and viewDidDisappear
for UIViewController
.
Thanks in advance!
I found an answer to this that works for this purpose, simply override didMoveToWindow
and check if self.window
is nil or not:
override func didMoveToWindow() {
if (self.window == nil) {
timerStop()
} else {
timerStart()
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With