Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bring Container to Front of View

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.

enter image description here

Debugging the views screenshot.

enter image description here

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?

like image 458
thank_you Avatar asked Jun 26 '15 01:06

thank_you


1 Answers

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.

Update

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
like image 166
ergoon Avatar answered Oct 05 '22 07:10

ergoon