【问题标题】:How to set Navigation bar and Tab bar as pass through views of a UIPopoverViewController?如何将导航栏和标签栏设置为通过 UIPopoverViewController 的视图?
【发布时间】:2018-01-12 05:05:35
【问题描述】:

我将 UIViewController 自定义为 PopoverViewController,当我展示它时,我无法触摸导航栏和标签栏

我搜索了一段时间,我得到了: 在第一个 ViewController 代码的 prepare(for segue: UIStoryboardSegue, sender: Any?) 中:

if segue.identifier == "ShowChoice"{
      let poper = segue.destination
      poper.modalPresentationStyle = .popover
      poper.popoverPresentationController?.delegate = self
      let point = CGPoint(x: self.view.bounds.midX, y: self.view.bounds.midY + 5)
      poper.popoverPresentationController?.sourceView = self.view
      poper.popoverPresentationController?.sourceRect = CGRect(origin: point, size: CGSize.zero)
      poper.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)

//here I set [self.view] to passthroughViews and it work i can interact with all thing in self.view but I can't interact with Navigation Button or Tab bar item!

            poper.popoverPresentationController?.passthroughViews = [self.view]
        }
    }

我只能将 UIView 设置为 passthroughViews 但我想设置导航栏或标签栏

谢谢!

【问题讨论】:

  • 您必须在此处显示更多上下文(更多代码),因为这对我来说很好。从您的代码行中,我们无法判断您尝试从哪里设置它,或者它是否全部正确连接。
  • @Terje 我更新了你能看看吗?

标签: ios swift ios-app-group


【解决方案1】:

有趣的是,popoverPresentationController.passthroughViews 中的项目顺序很重要!

例如,如果您想添加所有视图和导航栏,则必须将导航栏放在列表的开头,否则触摸只会被馈送到它下面的任何项目

这是我的代码:

 popoverPresentationController.passthroughViews = [self.view]
 if let navBar = self.navigationController?.navigationBar {
     popoverPresentationController.passthroughViews?.insert(navBar, at: 0)
 }

另外,如果您这样做,请记住关闭 popoverView 以便能够使用后退按钮

【讨论】:

    【解决方案2】:

    我终于自己找到了,只需将 [self.tabBarController?.tabBar,self.navigationController?.navigationBar] 转换为 [UIView]

    poper.popoverPresentationController?.passthroughViews = [self.tabBarController?.tabBar,self.navigationController?.navigationBar] as! [UIView]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多