iOS 11 navigationItem.titleView Width Not Set(iOS 11 navigationItem.titleView 宽度未设置)
问题描述
在 iOS11 上看到一个带有 navigationItem.titleView 的行为,其中 titleView 的宽度不是屏幕的全宽.
Seeing a behavior on iOS11 with a navigationItem.titleView where the width of the titleView is not the full width of the screen.
我有一个自定义视图,我设置为 titleView.在 iOS11 之前,视图将填充导航栏区域.但是 iOS 11 并没有调整大小来填充屏幕的宽度.
I have a custom view that I set as the titleView. Previous to iOS11 the view would fill the navigation bar area. But iOS 11 it is not resizing to fill the width of the screen.
我在设置 titleView 之前尝试设置视图的框架,但没有运气.我也尝试强制 titleViews 超级视图进行布局约束,但没有运气.
I've tried setting the frame of the view before setting titleView but no luck. I've tried to force the titleViews superview to layout constraints as well but no luck.
附上截图:
iOS10:
iOS11:
还有其他人经历过这种情况吗?
Anyone else experience this?
推荐答案
我想通了.我必须覆盖视图和文本字段的 intrinsicContentSize getter.
I figured it out. I had to override the intrinsicContentSize getter for the view, and the text field.
我将宽度设置为 CGFloat.greatestFiniteMagnitude,因此它始终与屏幕一样宽.
I set the width to CGFloat.greatestFiniteMagnitude so it'll always be as wide as the screen.
更新:
由于我已经在这个问题上花费了几个小时,希望其他人能够通过将所有事情紧密结合起来更快地赶上来
Since I've spent couple of hours on this issue, hope that some else will catch up faster by having all things tight up together
我创建了 TitleView 的自定义子类,名为 CustomTitleView,代码如下:
I've created a custom sub class of TitleView, called CustomTitleView, here's the code:
import UIKit
class CustomTitleView: UIView {
override var intrinsicContentSize: CGSize {
return UIView.layoutFittingExpandedSize
}
}
我从一开始就错过的最重要的部分是:
and the most important part which I missed from the start was this:
这篇关于iOS 11 navigationItem.titleView 宽度未设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:iOS 11 navigationItem.titleView 宽度未设置
基础教程推荐
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
