iOS 11上未点击navigationItem的自定义titleView [英] custom titleView of navigationItem is not getting tapped on iOS 11

查看:63
本文介绍了iOS 11上未点击navigationItem的自定义titleView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用自定义的titleView并将其分配给navigationItem titleView.在iOS 11之前,它一直可以正常工作.自更新以来,它的位置放错了中心,因为它原来位于左侧.除了用户交互无法正常工作之外.

I am using a custom titleView and assigning it to navigationItem titleView. It had been working fine until iOS 11. Since the update it's position got misplaced to center as originally it was on more left. Beside that user interaction is not working.

titleView = Bundle.main.loadNibNamed("SomeNib", owner: self, options: nil)?.first as? SomeNib
navigationItem.titleView = titleView

titleView只是一个普通的笔尖.

titleView is just a usual nib.

然后启用交互:

if let titleView = self.navigationItem.titleView {
            let tap = UITapGestureRecognizer(target: self, action: #selector(onTitleViewTap))
            titleView.addGestureRecognizer(tap)
            titleView.isUserInteractionEnabled = true
        }

推荐答案

在iOS 11中,titleView已通过Autolayout设置.因此,titleView的大小是您在titleView中设置的视图的固有大小.

In iOS 11, titleView is getting set with Autolayout. Hence, the size of the titleView is the intrinsic size of the view you are setting in titleView.

您的视图类中的此代码(您将其设置为titleView)应该会帮助:

This code in your view class(which you are setting as titleView) should help:

override var intrinsicContentSize: CGSize {
    return UILayoutFittingExpandedSize
} 

这篇关于iOS 11上未点击navigationItem的自定义titleView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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