IOS 11 navigation item with user interaction enabled not working

Viewed 906

Hi i have navigation item in there is a view which contains two labels i have added userInteractionEnabled for the view inside the navigation element (IBoutleted as navigationView)

navigationView.isUserInteractionEnabled = true

mainTitleClicked = UITapGestureRecognizer(target: self, action: #selector(mainTitleTapped))

self.navigationView.addGestureRecognizer(mainTitleClicked)

This was working in IOS 10 but when i run the same code in xcode 9 ios 11 UI is messed up and gesture is not getting recognised

enter image description here

IOS 10 Version

enter image description here

IOS 11 version

What should i change to make it work on ios 11

Thanks for the help

2 Answers

I Solved it By adding the following code

if #available(iOS 11.0, *) {
        self.navigationController?.navigationBar.prefersLargeTitles = false
        self.navigationItem.largeTitleDisplayMode = .automatic
        var width = navigationView.sizeThatFits(CGSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude)).width - 15.0
        let height = navigationView.sizeThatFits(CGSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude)).height

        let screenSize: CGRect = UIScreen.main.bounds
        let windowWidth = screenSize.width
        width = windowWidth * 0.55

        let widthConstraint = navigationView.widthAnchor.constraint(equalToConstant: width)
        let heightConstraint = navigationView.heightAnchor.constraint(equalToConstant: height)

        heightConstraint.isActive = true
        widthConstraint.isActive = true
    }

Making height and width constraint active was a answer given in another question i currently don't have the link to it will post the link in the edit (Currently i am unable to find that question)

I have this same problem and solved with this code too:

if #available(iOS 11.0, *) {
            self.navigationController?.navigationBar.prefersLargeTitles = false
            self.navigationItem.largeTitleDisplayMode = .automatic
            var width = popUserChatView.sizeThatFits(CGSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude)).width - 15.0
            let height = popUserChatView.sizeThatFits(CGSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude)).height


            let screenSize: CGRect = UIScreen.main.bounds
            let windowWidth = screenSize.width
            width = windowWidth * 0.55

            let widthConstraint = popUserChatView.widthAnchor.constraint(equalToConstant: width)
            let heightConstraint = popUserChatView.heightAnchor.constraint(equalToConstant: height)

            heightConstraint.isActive = true
            widthConstraint.isActive = true
        }

calling in ViewDidLoad()

Related