I have three controllers. One if the HomeViewController
that initiates the BlahPageViewController
and it's individual pages. The other two controllers (BlahPageViewController
and BlahItemViewController
deal with the UIPageViewController
exclusively. 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 forefront of the page. However when I run the app the buttons inside the container are not clickable.
Storyboard below.
Debugging the views screenshot.
What's wrong with this? Is there a better way to handle this. I don't want those buttons to move when the user flips through a page but the container is overlapped with the BlahItemViewController
? How can I fix this?
in your setPageViewController()
function you're using addSubview()
to add the view of the UIPageViewController to your ViewController's view. This will put the view on top of all other views.
Basically you have two options to avoid this. Either inserting it as the very first view using
self.view.insertSubview(pageViewController!.view, atIndex: 0)
or below a specific view using
self.view.insertSubview(pageViewController!.view, belowSubview: self.headerbar)
That should do the trick.
Also make sure that user interaction is enabled for the container view. There is a setting in Interface Builder but you can also do it in code:
self.headerbar.userInteractionEnabled = true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With