-1

I'm trying to embed a custom view in UIViewController. But when displayed, it's not clickable since it's out of the UIView frame.

storyboard screenshot

viewDidLoad:

@IBOutlet var theVC_InVC_Test: UIView!

@IBOutlet var TableView: UITableView!

override func viewDidLoad() {
    TableView.delegate = self
    TableView.dataSource = self

    func embed(_ viewController:UIViewController, inView view:UIView){
        viewController.willMove(toParent: self)
        viewController.view.frame = view.bounds
        view.addSubview(viewController.view)
        self.addChild(viewController)
        viewController.didMove(toParent: self)
    }
    embed(sidemenutest1(), inView: theVC_InVC_Test)

}

sidemenutest1 UIViewController:

func popItOver(){
    let PopOverVC = UIStoryboard(name:"Main",bundle: nil).instantiateViewController(withIdentifier: "CoinsPopUp") as! CoinsPopUpViewController
    self.addChild(PopOverVC)
    PopOverVC.view.frame = UIScreen.main.bounds
    self.view.addSubview(PopOverVC.view)
    PopOverVC.didMove(toParent: self)
}

@IBAction func storeAction(_ sender: Any) {
    popItOver()
}

simulator output

It's displayed fine, but it's not clickable... When I tried to click the subview buttons, the TableView is clicked and not the subview.

Parth
  • 2,682
  • 1
  • 20
  • 39
OneOfThem
  • 23
  • 6
  • “it's not clickable since it's out of the UIview frame.” Yes, a view outside its superview is not clickable. If you know that, what is the question? – matt Jan 08 '20 at 18:43
  • how to solve it. i don't want the side menu view to fit more that the given area but the pop up must came in the middle. – OneOfThem Jan 08 '20 at 18:45
  • Then don’t make the pop up a subview of the side menu. Or change the way hit testing works. – matt Jan 08 '20 at 18:48
  • it has to be this way, what is your recommendation to solve this issue. – OneOfThem Jan 08 '20 at 18:52
  • No it doesn’t “have to be this way”. – matt Jan 08 '20 at 19:18

1 Answers1

0

You shouldn't add the popover menu as a container view controller. It should be presented from the controller as a modal view controller instead and set its background view color to be the translucent gray color.

Caroline Harrison
  • 178
  • 1
  • 1
  • 9
  • could you write a sample code.i'm not sure how to do it since the button is in another view – OneOfThem Jan 08 '20 at 19:06
  • The button is inside a view controller somewhere. Present on that view controller like you would any other view controller: `self.present(vc, animated: true, completion: nil)` – Caroline Harrison Jan 08 '20 at 19:23