簡體   English   中英

如何將導航欄和標簽欄設置為通過UIPopoverViewController的視圖?

[英]How to set Navigation bar and Tab bar as pass through views of a UIPopoverViewController?

我自定義了一個UIViewController作為PopoverViewController,當我展示它時,我既不能觸摸導航欄,也不能觸摸選項卡欄

我搜索了一段時間,然后得到了:在第一個ViewController代碼的prepare(對於segue:UIStoryboardSegue,發件人: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,但我想設置導航欄或標簽欄

謝謝!

我終於找到了自己,只需將[self.tabBarController?.tabBar,self.navigationController?.navigationBar]強制轉換為[UIView]

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

有趣的是, popoverPresentationController.passthroughViews內部的項目順序popoverPresentationController.passthroughViews重要!

例如,如果您想添加所有視圖和導航欄,則必須將導航欄放置在列表的開頭,否則觸摸只會饋送到其下方的任何項目

這是我的代碼:

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

另外,請記住關閉popoverView,如果這樣做是為了能夠使用后退按鈕

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM