如何在ios11中修复导航栏标题位置 [英] How can I fix the navigationbar title position in ios11

查看:285
本文介绍了如何在ios11中修复导航栏标题位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是代码

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

viewControllerUIImagePickerController

当我在viewController中发言时,navigationbar标题发生了变化.

When I presented in viewController, navigationbar title shifted.

请检查图像.

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

Does anyone know how can I fix it?

推荐答案

您需要给titleView设置约束,因为iOS11导航栏中的约束正在播放约束,而不是像以前那样播放帧,

You need to give a constraint to titleView, from iOS11 navigation bar is playing with constraint instead of frames like before so,

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))

希望这会有所帮助!

这篇关于如何在ios11中修复导航栏标题位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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