IOS 11 navigation element with user interaction enabled does not work

Hi, I have a navigation element, there is a view that contains two labels that I 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 worked in iOS 10, but when I run the same code in xcode 9, the iOS 11 UI gets messed up and the gesture is not recognized

enter image description here

IOS version 10

enter image description here

IOS Version 11

What should I change to make it work on ios 11

thanks for the help

+4
source share
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
    }

, . , ( )

0

:

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
        }

ViewDidLoad()

0

Source: https://habr.com/ru/post/1686125/


All Articles