Bring the container to the front view.

I have three controllers. One, if HomeViewController , which initiates the BlahPageViewController and individual pages. The other two controllers ( BlahPageViewController and BlahItemViewController deal only with the UIPageViewController . In my HomeViewController , I have the following code that initializes the pages.

 private func setPageViewController() { let blahPageController = self.storyboard!.instantiateViewControllerWithIdentifier("BlahPageController") as! BlahPageViewController blahPageController.dataSource = self blahPageController.blahs = blahs if blahs.count > 0 { let firstController = getItemController(0)! let startingViewControllers: NSArray = [firstController] blahPageController.setViewControllers(startingViewControllers as [AnyObject], direction: .Forward, animated: false, completion: nil) } // Setting page view controller to front of app pageViewController = blahPageController addChildViewController(pageViewController!) self.view.addSubview(pageViewController!.view) pageViewController!.didMoveToParentViewController(self) // Now lets bring that container to the front. self.view.bringSubviewToFront(self.headerBar) // BUT IT DOESN'T WORK!!!! } 

I have to imagine that the container goes to the front of the page. However, when I launch the application, the buttons inside the container cannot be pressed.

Storyboard below.

enter image description here

Debug screen shots.

enter image description here

What happened to this? Is there a better way to handle this. I do not want these buttons to move when the user turns the page, but the container is overlapped using the BlahItemViewController ? How can i fix this?

+6
source share
3 answers

in your setPageViewController() function, which you use addSubview() to add the UIPageViewController view to the ViewController view. This will put the view on top of all other views.

Basically, you have two options to avoid this. Or inserting it as the very first view, using

 self.view.insertSubview(pageViewController!.view, atIndex: 0) 

or below a certain species using

 self.view.insertSubview(pageViewController!.view, belowSubview: self.headerbar) 

That should do the trick.

Update

Also ensure that user interaction is enabled for the container view. Interface Builder has a setting, but you can also do this in code:

 self.headerbar.userInteractionEnabled = true 
+4
source

I think the problem is what your pageview controller contains. You add the pageview manager view as a view representation of the dispatcher views, and then bring some headerBar to the front. It overlaps the view of the pageview controller.

Call

 self.headerBar.addSubview(pageViewController!.view) 

instead

 self.view.addSubview(pageViewController!.view) 
0
source

I think your view stacks are correct. You can check the container userInteractionEnabled, this is true. Or check if the buttons are accessible without adding a childview controller. This way you can see if the childviewcontroller affects the behavior of the buttons.

0
source

Source: https://habr.com/ru/post/989776/


All Articles