PreviewViewController

public class PreviewViewController : UIViewController
extension PreviewViewController: StyleManagerDelegate

PreviewViewController is a user interface for the preview mode experience. It allows to present banners that contain information that is important for the user before actually starting turn-by-turn navigation session (e.g. final destination presentation, main and alternative routes preview etc). By default Mapbox Navigation SDK provides such banners:

  • DestinationPreviewViewController - banner that is shown at the bottom of the screen and allows to show information about the final destination, preview available routes and start active navigation session
  • RoutePreviewViewController - banner that is shown at the bottom of the screen and allows to preview information about the current Route (expected travel time, distance and expected time of arrival)
  • BannerDismissalViewController - banner that is shown at the top of the screen and allows to dismiss already presented banner

Internally PreviewViewController relies on two components:

PreviewViewController works as an initial step before switching to the active navigation. Use NavigationViewController for turn-by-turn navigation experience.

  • Initializes a PreviewViewController that presents the user interface for the destination and routes preview.

    Declaration

    Swift

    public init(_ previewOptions: PreviewOptions = PreviewOptions())

    Parameters

    previewOptions

    Customization options for the navigation preview user experience.

  • Removes the top-most banner from the banners hierarchy.

    Declaration

    Swift

    @discardableResult
    public func dismissBanner(at position: BannerPosition,
                              animated: Bool = true,
                              duration: TimeInterval = 0.2,
                              animations: (() -> Void)? = nil,
                              completion: (() -> Void)? = nil) -> Banner?

    Parameters

    position

    Position of the Banner on the screen.

    animated

    If true, PreviewViewController animates the transition between banners.

    duration

    Duration of the animation. Defaults to 0.2 seconds.

    animations

    A block object containing the changes to commit to the views. This is where you programmatically change any animatable properties of the views in your view hierarchy. This block takes no parameters and has no return value.

    completion

    A block object to be executed when the animation sequence ends. This block has no return value.

    Return Value

    Banner that was dismissed. If there are no more banners in the banners hierarchy nil will be returned instead.

  • Removes all of the banners from the banners hierarchy except the first banner.

    Declaration

    Swift

    public func dismissAllExceptFirst(at position: BannerPosition,
                                      animated: Bool = true,
                                      duration: TimeInterval = 0.2,
                                      animations: (() -> Void)? = nil,
                                      completion: (() -> Void)? = nil)

    Parameters

    position

    Position of the Banner on the screen.

    animated

    Controls whether PreviewViewController animates the transition between banners. Defaults to true.

    duration

    Duration of the animation. Defaults to 0.2 seconds.

    animations

    A block object containing the changes to commit to the views. This is where you programmatically change any animatable properties of the views in your view hierarchy. This block takes no parameters and has no return value.

    completion

    A block object to be executed when the animation sequence ends. This block has no return value.

  • Adds the specified banner to the banners hierarchy and displays it.

    Declaration

    Swift

    public func present(_ banner: Banner,
                        animated: Bool = true,
                        duration: TimeInterval = 0.2,
                        animations: (() -> Void)? = nil,
                        completion: (() -> Void)? = nil)

    Parameters

    banner

    Banner instance that will be presented.

    animated

    Controls whether PreviewViewController animates the transition between banners. Defaults to true.

    duration

    Duration of the animation. Defaults to 0.2 seconds.

    animations

    A block object containing the changes to commit to the views. This is where you programmatically change any animatable properties of the views in your view hierarchy. This block takes no parameters and has no return value.

    completion

    A block object to be executed when the animation sequence ends. This block has no return value.

  • Returns the top-most banner in the banners hierarchy.

    Declaration

    Swift

    public func topBanner(at position: BannerPosition) -> Banner?

    Parameters

    position

    Position of the Banner on the screen.

    Return Value

    The top-most Banner. If there are no banners in the banners hierarchy nil will be returned instead.