恢复原始后退按钮行为

Restore original back button behavior

UIViewController viewDidLoad 方法中,我以这种方式自定义导航左按钮的图标和行为:

let backButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.action, target:self, action:#selector(handleBack))
self.navigationItem.leftBarButtonItem = backButton

有什么方法可以恢复它原来的外观和行为吗?

你必须这样做:

viewDidLoad方法中,添加:

self.navigationItem.hidesBackButton = YES;
let backButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.action, target:self, action:#selector(handleBack))
self.navigationItem.leftBarButtonItem = backButton;

要还原,请执行以下操作:

self.navigationItem.leftBarButtonItem = nil;
self.navigationItem.hidesBackButton = NO;
self.navigationItem.leftBarButtonItem = nil
self.navigationItem.hidesBackButton = NO

导航栏只支持这些

我用 this 提取了 iOS assets assets 并且校准后退按钮以使其看起来不假是很烦人的,即使我使用了提取的,我的建议是让导航控制器通过保持推入堆叠时出现的背面来为您处理这个问题。