Search code examples
iosswiftios-app-group

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


I have custom a UIViewController as a PopoverViewController and when I present it I can't touch on Navigation bar neither Tab bar

I have search for while and I got: In prepare(for segue: UIStoryboardSegue, sender: Any?) of first ViewController code:

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]
        }
    }

I can set only UIView to passthroughViews but I want to set Navigation Bar or Tab Bar

thank you!


Solution

  • I finally found on my own by simply cast [self.tabBarController?.tabBar,self.navigationController?.navigationBar] to [UIView]

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