iOS 7 UINavigationBar has hidden back button

2019-04-12 01:05发布

问题:

I have an app which has a back button with a custom image in its UINavigationBars. In iOS 6 everything is fine but in iOS 7 the button is 'invisible' most of the time.

When I push a new view controller into the UINavigationController the back button does not appear for the new screen, though if I touch where the button is supposed to be it fades in.

If I set two view controllers on the navigation controller without animation then the button shows up fine but doesn't appear for subsequent pushes.

I'm pretty sure there's nothing in my code that's intentionally hiding the back button and changing the various colours available on the UINavigationBar doesn't make any difference.

回答1:

This is probably due to two new UINavigationBar properties introduced in iOS 7 that you have to implement:

self.navigationController.navigationBar.backIndicatorImage = [UIImage customImage]; self.navigationController.navigationBar.backIndicatorTransitionMaskImage = [UIImage customImage];

From iOS 7 Transition Guidelines:

"If you want to use a custom image to replace the default chevron, you also need to create a custom mask image. iOS 7 uses the mask to make the previous screen’s title appear to emerge from—or disappear into—the chevron during navigation transitions. To learn about the properties that control the Back button and mask image, see UINavigationBar Class Reference."