iOS14 长按返回按钮 backButtonDisplayMode

iOS 14中长按返回按钮会显示多级菜单,滑动后可以返回对应的页面。


navigation stack.gif

在App上长按后title为空


空白.png

backButtonDisplayMode

iOS 14新增了一个属性backButtonDisplayMode来定义title的来源

typedef NS_ENUM(NSInteger, UINavigationItemBackButtonDisplayMode) {
    /// Default mode, uses an appropriate title, followed by a generic title (typically 'Back'), then no title.
    UINavigationItemBackButtonDisplayModeDefault = 0,
    /// Generic titles only. Ignores .title and .backButtonTitle (but *not* .backBarButtonItem.title).
    UINavigationItemBackButtonDisplayModeGeneric = 1,
    /// Don't use a title, just the back button indicator image.
    UINavigationItemBackButtonDisplayModeMinimal = 2,
} NS_SWIFT_NAME(UINavigationItem.BackButtonDisplayMode);

title来源的优先级
1.navigationItem.backBarButtonItem
2.navigationItem.backButtonTitle
3.navigationItem.title和viewController的title,同时设置显示为viewController的title

App中使用

UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = item;

来隐藏返回按钮的标题,引起了上面的问题。

UINavigationItemBackButtonDisplayModeMinimal

Minimal模式下,返回按钮不显示title,但是 navigation stack可以显示出 title,未设置title的时候显示返回。

适配

    if (@available(iOS 14.0, *)) {
        self.navigationItem.backButtonDisplayMode = UINavigationItemBackButtonDisplayModeMinimal;
    } else {
        UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
        self.navigationItem.backBarButtonItem = item;
    }
适配.png

你可能感兴趣的:(iOS14 长按返回按钮 backButtonDisplayMode)