cynistersix
cynistersix

Reputation: 1215

How to get UIPageViewController to not clipToBounds

I need to overlay a UIView over a UIPageViewController and was hoping it would let me turn off the clipsToBounds and then resize the interactive bounds area to a smaller height and place another view on top of the non-interactive/non-clipped region.

Unfortunately the UIPageViewController resizes the childViewController in some way where it will clip it no matter what.

What I want is something like this:

How can I achieve this? I can find no samples of doing anything like this and did try to use the UICollectionViewController instead with paging but it doesn't have the smooth gaps between pages like the UIPageViewController does.

Upvotes: 4

Views: 1800

Answers (3)

Fattie
Fattie

Reputation: 12277

Curiosity ...

If the page view controller is set to the "curl" mode, in fact it anyway has NO clipping. Who knew?

The fix ...

Thanks to Brian and Vitaly

class FixedPVC: UIPageViewController {
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        view.clipsToBounds = false
        for v in view.subviews { v.clipsToBounds = false }
    }

}

Upvotes: 0

Brian Sachetta
Brian Sachetta

Reputation: 3463

The following works for me in Swift:

pageViewController.clipsToBounds = false
pageViewController.view.clipsToBounds = false
for view in pageViewController.view.subviews {
    view.clipsToBounds = false
}

Similar to Vitaly's answer, but uses a loop to ensure that all subviews are taken care of.

Upvotes: 5

vitalytimofeev
vitalytimofeev

Reputation: 291

View of UIPageViewController has another UIView (more precisely _UIQueuingScrollView) in the subviews hierarchy before actual view of your childViewController. So, to disable clipsToBounds you should do something like that:

UIPageViewController *pageViewController = ...;
pageViewController.view.clipsToBounds = NO;
[[pageViewController.view subviews].firstObject setClipsToBounds:NO];

Upvotes: 5

Related Questions