【问题标题】:How can I fix the navigationbar title position in ios11如何修复ios11中的导航栏标题位置
【发布时间】:2017-12-15 10:44:01
【问题描述】:

这里是代码

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

viewControllerUIImagePickerController

当我在viewController 中发表演讲时,navigationbar 的标题发生了变化。

请检查图片。

有人知道我该如何解决吗?

【问题讨论】:

    标签: objective-c uiimagepickercontroller ios11 navigationbar


    【解决方案1】:

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

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

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

    【讨论】:

      【解决方案2】:

      你需要给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))
      

      希望这会有所帮助!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-27
        • 1970-01-01
        • 1970-01-01
        • 2017-03-30
        • 1970-01-01
        相关资源
        最近更新 更多