I see viewIsAppearing
is available on iOS 13 and above, but when I use it, found that the function not be called below iOS 16
https://developer.apple.com/documentation/uikit/uiviewcontroller/4195485-viewisappearing
environment: Macos 14.4.1, Xcode 15.3
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let sub = SubViewController()
addChild(sub)
view.addSubview(sub.view)
}
@available(iOS 13.0, *)
override func viewIsAppearing(_ animated: Bool) {
super.viewIsAppearing(animated)
print("ViewController viewIsAppearing")
}
}
class SubViewController: UIViewController {
@available(iOS 13.0, *)
override func viewIsAppearing(_ animated: Bool) {
super.viewIsAppearing(animated)
print("SubViewController viewIsAppearing")
}
}
In iOS 15 devcice console log:
ViewController viewIsAppearing
iOS 16, 17:
ViewController viewIsAppearing
SubViewController viewIsAppearing
There is a known issue with the viewIsAppearing(_:)
callback when running on older iOS versions (prior to iOS 16) where it may not be called in certain circumstances when you have nested child view controllers. If you are still supporting those older iOS versions and encounter a situation like this, you will need to implement a workaround in your app when running on those older versions to ensure that the code you would normally run in viewIsAppearing(_:)
still executes when you need it to.