Ninja
Ninja

Reputation: 358

Is there a situation when traitCollectionDidChange is the only function that can not be substituted by willTransition?

Apple says that traitCollectionDidChange(... called when the iOS interface environment changes and willTransition(to:with:) Notifies the container that its trait collection changed. ok. but is there a code i must call strictly in traitCollectionDidChange and not in willTransition and not in viewWillTransition? Why do we need separate traitCollectionDidChange( function? is there condition where we can not substitute traitCollectionDidChange with willTransition???

class VC : UIViewController {
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
    print("\(type(of:self)) \(#function)")
    super.traitCollectionDidChange(previousTraitCollection)
}
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
    print("\(type(of:self)) \(#function)")
    super.viewWillTransition(to: size, with: coordinator)
}
override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) {
    print("\(type(of:self)) \(#function)")
    super.willTransition(to: newCollection, with: coordinator)
}
}

Upvotes: 2

Views: 326

Answers (0)

Related Questions