iOS 11导航TitleView放错地方 [英] iOS 11 Navigation TitleView misplaced

查看:377
本文介绍了iOS 11导航TitleView放错地方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iOS应用程序,我在其中设置自定义导航标题视图。

I have an iOS app in which I am setting a custom navigation title view.

在iOS 10中工作正常,但在iOS 11中导航标题视图放错了地方。

以下是iOS 10的屏幕截图 -

以下是iOS 11的屏幕截图 -

正如您在屏幕截图中看到的那样当我在iOS 10上运行代码时,标题视图似乎没问题。但是iOS 11上的相同代码会将标题视图向下移动一些像素并且会被切断。

As you can see in the screen shots that when I run the code on iOS 10 the title view appears to be fine. But the same code on iOS 11 shifts the title view down by some pixels and it gets cut.

这就是我设置标题视图的方式 -

This is how I am setting the title view -


navigationItem.titleView = MY_CUSTOM_TITLE_VIEW

我尝试了很多东西并搜索了许多解决方案,但没有任何工作。

I tried many things and searched for many solutions but nothing is working.

推荐答案

以下是它的具体方法可以修复 -

Here's how it can be fixed -

在自定义标题视图类中添加此代码 -

Add this code in the custom title view class -

override var intrinsicContentSize: CGSize {
    return UILayoutFittingExpandedSize
}

和自定义标题视图显示在正确的位置。

And the custom title view shows up at the correct position.

这篇关于iOS 11导航TitleView放错地方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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