UINavigationBar Touch

前端 未结 9 1292
北恋
北恋 2020-12-23 17:53

I would like to fire an event on touch when a user taps the title of the navigation bar of one of my views.

I\'m at a bit of a loss on whether I can access the view

9条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-23 18:06

    This is the simplest and easiest solution in Swift, just copy/paste and fill in the blanks:

    let navTapGesture = UITapGestureRecognizer(target: <#T##AnyObject?#>, action: <#T##Selector#>)
    navigationItem.titleView.userInteractionEnabled = true
    navigationItem.titleView.addGestureRecognizer(navTapGesture)
    

    Be sure to set the userInteractionEnabled to true on the titleView, its off by default.

提交回复
热议问题