Vertical View Pager either in Swift or in Objective C - ios

Is it possible to implement Vertical ViewPager or not?
if Yes the please suggest me how to do it.
I am working on an app, which is similar to Quiz App.
I want to implement Quiz App result screen in which I am looking to implement Vertical View pager.
Thank you
Abhishek

So that's simply a scroll view, or a subclass of (I.e. A table or collection view). The scroll direction is controlled by the content size (or the layout for the collection). Any scroll view can have paging enabled.
If using a table or collection you simply need to set the row height or item size to the size of the view. For a plain scroll view you add the page views as sub views and set their size to equal the scroll view frame.

Related

Nested scrollview with table view in ios

I have a scroll (Scroll view 1) view which contains profile View and Custom Segmented Control which replaces the content in the nested scroll view (Scroll view 2). On segmented control tab change I added the table view inside nested scroll view (Scroll view 2). I am not able to scroll to the whole view. How can I achieve this?
one simple solution is to calculate your nested scroll's content height and give it a fixed height constraint so it wont be able to scroll by itself anymore
but a little more complicated solution is HERE
I hope it helps

One section of the view controller is still and one section horizontally scrollable

I would like to construct a view controller where one section of the view controller would be still and one section scrollable.
Both sections have headers where as well, one is still and one is moving along with the content in the section.
I do not want the cells in the section to be scrolled separately. All cells should move at the same time along with the header.
I have added an image to make my point little more clearer.
Use UICollection View for both view and disable scrolling for one view and enable scrolling for another view
you can probably add to your UIViewController view a UITableView on the left with fixed size (for example 150px) and vertical scroll disabled and a UICollectionView with horizontal flow and ,if needed a, with custom UICollectionViewLayout (but i think that you just need the classic UICollectionViewFlowLayout) for the right part that fits the remaining space.
Here you can find the component's documentation:
https://developer.apple.com/reference/uikit/uicollectionview
https://developer.apple.com/reference/uikit/uitableview

How to horizontally scroll between pages of controls in UIScrollView iOS/Swift

I am trying to find the way to implement a scroll view on my viewController screen, which allows the user to scroll between different pages of controls and have the controls around it, outside the scroll view, react to whatever data or actions take place in the scroll view.
All the tutorials I have found is adding a scroll view that shows a carousel of images, or programmatically adding coloured frames. Very little control interaction.
But none that shows how to create 2-3 pages of controls (buttons and labels), and how to integrate it with the parent view (so the parent view and scroll view talk to each other in one view).
So for now, what would be the first step to create a scroll view with 2 'pages' of controls? Has anyone come across any good resources for this? How is the best way to achieve this?
Thanks!
Add Scroll View. Add top,left,right, bottom constraint to scroll view. Set horizontal only in storyboard.
Add a view inside scroll view. Now add height constraint from this view to super view. (Not the scroll view.) Specify some width and add width constraint.
I suggest you to use UIPageViewController for this type of scrolling.
I suggest you go for UICollectionViewLayout and enable paging to true. Using this will give you the finest control of each page and the horizontal as well as vertical scroll.

Using vertical UIScrollView with horizontal paging

So, what I need: 3 pages (with swipe support): two of them just fit the screen, third one must have vertical scrolling.
1) Can you provide what bunch of controls I need to use: ScrollView with vertical scrolling inside parent ScrollView with paging enabled? Or ScrollView with PageControl?
2) How to adjust vertical ScrollView. I've read bunch of question here, and tried to do that by myself.
I tried to add 4 constraints for ScrollView (pin it to parent edges), then I add child UIView, also pin it to Scroll edges. Then I add some rectangles to child view, and using different settings I got: just horizontal view, horizontal+vertical scroll, only vertical scroll but with top space from UINavigationBar and with clipped some height from child rectangles (I can't scroll to them).
Can someone provide some example of how to do that? I prefer IB for constraints, but if it's necessary to calculate some math in code - it's ok.
Thanks
When paging between view's like that, I would suggest using a UIPageController (You can easily get a sample application by creating a new project and selecting "Page Based Application"). Change the transition style from Page Curl to Scrolling and there is the functionality you need for paging between view controllers. Now you just can place a scroll view in your third view controller and make sure the attributes are as follows. DirectionLockEnabled is the key to what you are trying to do, as it determines if scrolling is disabled in a particular direction (this case horizontal scrolling). Using this type of solution, it is then really easy to set constraints because you're setting constraints for 3 separate view controllers rather than 3 views within a scroll view
edit: disable "Shows Horizontal Indicator" Checkbox also

How should I approach structuring this view?

I'm having a hard time finding the best way to structure this design.
The top view has a minimum height and becomes sticky when it reaches this height. The bottom view hosts a paging controller with three views within. Each of these views hosts either a collection view or table view with vertical scrolling.
I'm really at a loss on how to approach this. Is the entire view scrollable and I should prevent scrolling on the second view until the top view has reached it's sticky height? Or are each of these views separate uitableviews and the pagingcontroller is just one cell? Should I even be using a pagingcontroller or should I use a scrollview with paging enabled? (the latter was a little rough interaction-wise)
Thank you!
Take a look at the Advanced User Interfaces using Collection View from WWDC this year. This view is very very very similar to the iTunes Connect app interface. The entire session video explains how they created that interface.
I used a similar method to this to create the keyboard in the Emojicate app.
I think what I'd do is actually fake the sticky header. So something like this...
Use only one collection view.
Create a "segmented data source" that contains three data sources. (See the video from WWDC about this)
When the segmented control is changed then update the collection view by changing its layout and (if you want) dataSource.
Make the entire top section a header on the collection view.
When the collection view scrolls past a certain point (when you want to sticky the header) then have a second view that is the compressed header and make it visible at the top of the screen. This is not attached to the collection view at all.
When the segmented control changes you can update the collection view by changing the "selected datasource". The datasource can also contain a UICollectionViewLayout that will update it.
Essentially, the tableview you are talking about is just a collection view where the cell width is equal to the screen width. i.e. fake a table view.
The sticky header isn't sticky at all. Just when it starts to go off screen you can put a fake header there instead.
It will require a duplicate (ish) view and some thinking about how to structure the data but I think this will be easier and less resource hungry than having multiple collection views and page controller and stuff.
If you want me to go through it in more detail let me know but it's a complex subject. Watch the video first.
I would make this part a navigation bar. Should be relatively easy. Just have to customize the back button with a barButtonItem and do a couple of labels in the titleView.
I would make the next part a Table View.
The tableView has 2 sections. The first section doesn't have a section header and the second section doesn't have any cells but just a section header.
First and only cell in this section:
And the rest would be the second section header's view:
This gives you the stickiness that you want because the section header will remain there even if you scroll past it and since the collection has only 2 sections the controls will always remain on top.
I think the collection/table paging part is the hardest part and I don't know clearly how it can be done. But I was thinking it could perhaps be a ContainerView. Each view of the container view would be either a tableview or a collectionview. You would have to add some code to handle the movement of the containerview relative to the second section header (possibly an autolayout constraint that attaches the containerview to the buttom of the first tableview that you implemented above).
I don't think having your tables/collections in a scrollview would be a good implementation. I think I have even read in documentation that developers should stay away from that (but I might be remembering it incorrectly).
I would have:
A "header view" with three subviews:
Fixed height top and bottom views (they stay visible at any size).
A middle view that appears/disappears as the superview grows/shrinks.
A scroll view (table or collection view are subclasses) on that partially covers the header view with a top inset set enough to reveal the underlying header view (the same way pull to refresh views are revealed).
The paging buttons could be set as table/collection view section header views.
Finally track the scroll view's scroll position to keep manually adjusting the header view height.
Another way to see this solution.
Two completely separated parts, a header view and a table view.
A simple header view (blue) that adjusts its subviews as its height changes. More precisely hides its middle subview (light blue) when it shrinks.
A table view that a) partially covers the header view in Interface builder but b) has a top inset as to avoid hiding the header view in the actual device (tableView.contentInset = UIEdgeInsetsMake(60.0f, 0.0f, 0.0f, 0.0f);).
The two parts are only "connected" by resizing the header view height as the table view scrolls up/down.

Resources