如何修复ios11中的导航栏标题位置

时间:2017-12-15 10:44:02

标签: objective-c uiimagepickercontroller ios11 navigationbar

这是代码

[self presentViewController:viewController animated:YES completion:nil];

viewControllerUIImagePickerController

当我在viewController中展示时,navigationbar标题已移位。

请检查图像。

I'm the image

有谁知道我该如何解决?

2 个答案:

答案 0 :(得分:0)

使用以下方法自定义和更改导航栏按钮

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
 {
          //---> Code
 }

有关更多信息,请参阅以下链接: Link

答案 1 :(得分:0)

你需要给titleView一个约束,从iOS11导航栏播放约束而不是之前的帧,

public extension UIView {
//From iOS 11 -> UIBarButtonItem uses autolayout instead of dealing with frames. so adding contraint for the barbuttonItem
public func applyNavBarConstraints(size: (width: CGFloat, height: CGFloat)) {
    if #available(iOS 11.0, *) {
        let widthConstraint = self.widthAnchor.constraint(equalToConstant: size.width)
        let heightConstraint = self.heightAnchor.constraint(equalToConstant: size.height)
        heightConstraint.isActive = true
        widthConstraint.isActive = true
    }
}}

并使用如下:

navigationItem.titleView.applyNavBarConstraints(size: (width: viewWidth, height: viewHeight))

希望这有帮助!