为什么三个按钮出现在iOS 11导航backBarButtonItem的位置?

问题描述:

我已经设置了UINavigation栏外观看起来像follwing,为什么三个按钮出现在iOS 11导航backBarButtonItem的位置?

代码:

fileprivate class func barButtonAppearance() { 
    var attributes = [String : AnyObject]() 
    attributes[NSFontAttributeName] = UIFont(name: .Regular, size: 14) 
    attributes[NSForegroundColorAttributeName] = UIColor.descriptionColor() 
    UIBarButtonItem.appearance().setTitleTextAttributes(attributes, for: UIControlState()) 

    let backImage = UIImage.image(assetID: .NavigationBarBack, caps: UIEdgeInsetsMake(0, 23, 0, 0)).withRenderingMode(.alwaysTemplate) 
    UIBarButtonItem.appearance().setBackButtonBackgroundImage(backImage, for: .normal, barMetrics: .default) 

    UINavigationBar.appearance().backIndicatorTransitionMaskImage = backImage 
} 

这是工作的罚款,直到我们在iOS的11

考验了我们的应用程序如果我的评论下面的代码

let backImage = UIImage.image(assetID: .NavigationBarBack, caps: UIEdgeInsetsMake(0, 23, 0, 0)).withRenderingMode(.alwaysTemplate) 
UIBarButtonItem.appearance().setBackButtonBackgroundImage(backImage, for: .normal, barMetrics: .default) 

它工作正常,但与默认苹果给回按钮。

这里是出现在导航栏的屏幕截图,

enter image description here

我是不是能够得到什么事。有人可以提出我的解决方法吗?谢谢。

+0

任何运气。我也遇到同样的问题 –

+0

不,我以不同的方式解决问题。我添加了一个左侧导航按钮,并在BaseViewController中有一个通用方法来弹出ViewControllers。 –

+0

我找到了方法,请查看我的答案。它将适用于所有的ios版本。 –

UINavigationBar.appearance().backIndicatorImage = image.withRenderingMode(.alwaysOriginal) 
UINavigationBar.appearance().backIndicatorTransitionMaskImage = image.withRenderingMode(.alwaysOriginal) 

if #available(iOS 11, *) { 
    UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.clear], for: .normal) 
    UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.clear], for: .highlighted) 
} else { 
    UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffset(horizontal: -60, vertical: -60), for: .default) 
} 

图像的UIImage。无需在每个控制器上创建基本控制器或编写代码。只需将这些行放入应用程序委托中即可。

您可以使用此方法:

func addBackButton() { 
    let leftButton = UIBarButtonItem(image: Asset.backIco, style: UIBarButtonItemStyle.Plain, target: self, action: #selector(self.popViewControllerAnimated(_:))) 
    self.navigationItem.leftBarButtonItem = leftButton 
} 

在扩展的UIViewController

贴吧