TipUIPopoverViewController
A view controller that displays a popover tip in UIKit applications.
Declaration
@MainActor @objc @preconcurrency final class TipUIPopoverViewControllerOverview
Use this view controller to present a tip you want to display using UIPopoverPresentationController.
Presenting or dismissing TipUIPopoverViewController is done by listening to a tip’s shouldDisplayUpdates or statusUpdates.
import TipKit
import UIKit
struct CatTracksFeatureTip: Tip {
var title: Text {
Text("Sample tip title")
}
var message: Text? {
Text("Sample tip message")
}
var image: Image? {
Image(systemName: "globe")
}
}
class CatTracksViewController: UIViewController {
@IBOutlet weak var catTracksFeatureButton: UIButton!
private var catTracksFeatureTip = CatTracksFeatureTip()
private var tipObservationTask: Task<Void, Never>?
private weak var tipPopoverController: TipUIPopoverViewController?
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
tipObservationTask = tipObservationTask ?? Task { @MainActor in
for await shouldDisplay in catTracksFeatureTip.shouldDisplayUpdates {
if shouldDisplay {
let popoverController = TipUIPopoverViewController(catTracksFeatureTip, sourceItem: catTracksFeatureButton)
present(popoverController, animated: animated)
tipPopoverController = popoverController
}
else {
if presentedViewController is TipUIPopoverViewController {
dismiss(animated: animated)
tipPopoverController = nil
}
}
}
}
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
tipObservationTask?.cancel()
tipObservationTask = nil
}
}