programmist
programmist

Reputation: 594

UIPageViewController resize child view to reserve space for itself

I am developing an iPhone application for ios 7.1. The ViewController hierarchy is like "NavigationController -> UIViewController -> UIPageViewController -> UITableViewControllers". NavigationBar is hidden. Status bar is present. Everything is done programmatically. No storyboard/Xib is used.

In the UIPageViewController, I am creating a custom Title view (similar to the Navigation bar, but inside its own view). Hence the child controller's view (UITableView) should be pushed below this Title View. I have tried adding a constraint ("V:[TitleView]-0-[ChildView]"), after setting translatesAutoresizingMaskIntoConstraints of child view to NO. But this resulted in a blank screen (except for the title view). Changing frame of the child view etc and all did not have any effect.

Apart from setting the above flag and adding the constraint, I have not added/modified any auto layout/auto resize related settings. The application supports only the portrait mode (Home button down). There is not going to be any other dynamic layout change either. Appreciate if you could help in resolving this issue.

Upvotes: 0

Views: 2917

Answers (2)

programmist
programmist

Reputation: 594

Following is the solution I ended up with as of now. Project was on hold for some time, and now being rewritten in Swift. Hence the below code is in swift.

//in the UIPageViewController
override func viewDidLayoutSubviews()
{
    super.viewDidLayoutSubviews()

    let scrollView = view.subviews[0] as UIView
    scrollView.frame = CGRectMake(scrollView.frame.origin.x, 64, scrollView.frame.size.width, scrollView.frame.size.height - 64)
}

Basically I am moving and resizing the Page controller's default scroll view below my title view. I have to admit that I am not very happy with the solution. I feel that there must be some better alternative. (To make it safer, you can iterate the subviews to find the scroll view).

Upvotes: 3

Plokstorm
Plokstorm

Reputation: 27

Look at the autoresize constraint from your page view controller and set it to false.

I think it's not the child which are autoresize but the pageviewcontroller frame.

Upvotes: 1

Related Questions