【问题标题】:Add subView behind items to UINavigationBar in iOS 11在 iOS 11 中将项目后面的子视图添加到 UINavigationBar
【发布时间】:2017-08-14 09:01:35
【问题描述】:

在我的UINavigationBar 子类中,我添加了一个带有insertSubview(customView, at: 0) 的子视图,以便将它放在UINavigationBar 的“后面”。

在 iOS 10 中,添加的 subView 将根据我的需要添加 Title 和 UIBarButtonItems,但在 iOS 11 中,Apple 似乎改变了一些东西,因为无论我尝试什么,customView 都会被放置在UINavigationBar的前面。

//containerView
containerView.frame = CGRect(x: 0, y: -(statusBarHeight), width: UIScreen.main.bounds.width, height: frame.height + statusBarHeight)
containerView.clipsToBounds = true

insertSubview(containerView, at: 0)

我已经尝试过更改索引。

知道我应该如何解决这个问题吗?

【问题讨论】:

  • 我添加了代码
  • 遇到同样的问题 iOS 11 beta 9

标签: swift xcode uinavigationbar ios11


【解决方案1】:

你可以看看这个。我是这样解决的:

override func layoutSubviews() {  
        super.layoutSubviews()  
        for aView in self.subviews {  
            if NSStringFromClass(type(of: aView)) == "_UINavigationBarContentView" {  
                aView.frame = CGRect(x: 0, y: 20, width: aView.frame.width, height: aView.frame.height)  
            }  
            else if NSStringFromClass(type(of: aView)) == "_UIBarBackground" {  
                aView.frame = CGRect(x: 0, y: 0, width: aView.frame.width, height: self.frame.height)  
            }  
        }  
    }  

【讨论】:

  • 请提取解决方案并将其作为答案发布。不要简单地链接到其他网站
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多