后退按钮在UINavigationController中奇怪地消失但仍在继续工作 [英] Back button strangely disappearing in UINavigationController but keeps working

查看:71
本文介绍了后退按钮在UINavigationController中奇怪地消失但仍在继续工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS7下,我遇到了一个问题,如果使用特定的背景图像设置后退按钮项目将不会显示:

Under iOS7 I've been experiencing an issue where the back button item will not show up if it has been set with a specific background image:

int imageSize = 21; //REPLACE WITH YOUR IMAGE WIDTH

[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-400.f, 0)
                                                   forBarMetrics:UIBarMetricsDefault];
UIImage *barBackBtnImg = [[UIImage imageNamed:@"BackArrowDark.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, imageSize, 0, 0)];

[[UIBarButtonItem appearance] setBackButtonBackgroundImage:barBackBtnImg
                                                forState:UIControlStateNormal
                                              barMetrics:UIBarMetricsDefault];

执行此操作后,我在导航控制器中按下的任何ViewController都不会出现后退按钮项,即使按下它应该的位置,也会显示它,并且此视图控制器的任何后续推动都会在屏幕上显示该按钮。

Upon doing this, any ViewController that I push in the navigation controller will have no back button item appearing, even though pressing where it should be, will make it appear, and any subsequent pushes of this view controller will have the button present on the screen.

此问题仅出现在iOS7下:一切都在iOS6下完美运行。

This issue is only appearing under iOS7: everything works perfectly under iOS6.

使用leftBarButtonItem完全更改后退按钮会禁用后滑动,因此这不是一个选项。

Changing the back button completely with a leftBarButtonItem disables the back swipe, so that is not an option.

我知道我做错了什么?

非常感谢您的考虑。

推荐答案

在尝试不同的解决方案之后,我发现在iOS7下更改backIndicatorImage效果最好,它似乎与iOS7界面范例一致:

After trying different solutions, I found that changing the backIndicatorImage works best under iOS7, and it seems to be in line with the iOS7 interface paradigm:

[[UINavigationBar appearance] setTintColor:[UIColor grayColor]];
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault]; // Takes out title

UIImage *backButtonImage = [UIImage imageNamed:@"BackArrowDark.png"];

if ([UINavigationBar instancesRespondToSelector:@selector(setBackIndicatorImage:)]) {
  [[UINavigationBar appearance] setBackIndicatorImage:backButtonImage];
  [[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:backButtonImage];
} else {
  int imageSize = 21; // REPLACE WITH YOUR IMAGE WIDTH

  [[UIBarButtonItem appearance] setBackButtonBackgroundImage:[backButtonImage resizableImageWithCapInsets:UIEdgeInsetsMake(0, imageSize, 0, 0)] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
}

使用此方法:


  • 当返回导航控制器时,后退按钮项目转换与默认指示器相同(在iOS6下,后退按钮也会滑离;)

  • 在iOS6下,backButton已更改并保持其默认的iOS6行为。

  • 我很高兴!

这篇关于后退按钮在UINavigationController中奇怪地消失但仍在继续工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆