简体   繁体   中英

iOS/Swift/Storyboard: Add PageViewController using only *part* of screen?

New to Swift. I've seen many tutorials on using PageViewController, but they always have the Page View taking up the whole screen.

I'm trying to implement a Page View functionality in only PART of my app, not the entire screen, so that other "static" elements (eg a ToolBar) can remain. Something that would look kinda like this...

https://imgur.com/9wM1vll --- (Need more rep. before embedding images)

...where swiping will cause different images to appear as seen in various PageViewController tutorials (eg http://www.appcoda.com/uipageviewcontroller-storyboard-tutorial/ ).

When I start with a Single View Application, I go to Storyboard and try to drag a "Page View Controller" from the Object Library into the ViewController frame, it just "bounces back", ie it won't let me add the Page View Controller.

Now, if I add the Page View Controller to the white space around the other View Controller, then this gets back to the tutorials where the PageViewController takes up the entire screen and I don't want that.

How does one achieve this?

Thanks.

Sorry if this is a dupe but I have tried & failed to find anything that answers my question directly. The closest are Implement PageViewController in TableViewController details or Adding a UIPageViewController to a subview, subview only shows edge of pageContentview , but these are not similar enough for me to comprehend, plus they're in Objective C which I've not yet learned.

When I start with a Single View Application, I go to Storyboard and try to drag a "Page View Controller" from the Object Library into the ViewController frame, it just "bounces back", ie it won't let me add the Page View Controller.

A page view controller is a view controller. Thus, to make its view occupy only part of the screen, you must obey the rules for view controllers in general: you need a custom parent view controller, and the page view controller must be its child view controller — and you must do the elaborate dance that this entails when you create the child and put its view into the interface.

To get the storyboard to do the dance for you, use a Container View and hook it by its embed segue to the page view controller:

在此处输入图片说明

在此处输入图片说明

(Still, in my opinion it is always better to learn to do the dance manually, in code, yourself.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM