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

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.

Related

Horizontal scroll view not scrolling

I've just vertical scrolling a few times in the past, but now I'm trying to implement horizontal scrolling but when I run it it doesn't scroll.
What is the problem with it?
P.S. is it possible to design and layout views using a storyboard for scrolling? In this example the blue view is still visible within the screen representation, so its ok to deal with, but suppose I wanted to add another view which is further to the right and thus not visible within the screen representation? Is there anyway of visually designing a scroll view where you can see all the entirity within the storyboard what it will look like?
You don't have a trailing constraint on the scroll view's direct subview, so the scroll view cannot compute the correct contentSize.
Also, it's easier to understand the constraints in the document outline if you give each view a unique label. You have two views labelled “View” so it's difficult to be sure which constraints connect to which “View”.

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

Scrollview won't scroll all the way down

I have a scroll view which works fine. Almost. I'm building in Any/Any. The problem is that the scroll view won't scroll past the view controller. I have a switch that is mostly in the view controller window, but the rest is off the box (not really sure how to describe it; it's in the view in the scroll view, but the view is longer than the view controller so part of it is hidden).
The scroll view will scroll down until it hits the part where the view controller would end if you were looking at it in Xcode. There is some more stuff under the switch (labels and another switch). To view these you have to forcefully scroll down. Xcode shows no constraint errors (little red circle with white arrow).
Hopefully this makes sense
A ScrollView needs to know the height and width of the content it is holding in order to know how much to scroll and which direction. Here is a quick read on how ScrollViews work in iOS: https://www.objc.io/issues/3-views/scroll-view/
You can set this programmatically using the contentSize property, but this requires you to know and or calculate the contentSize, which is pretty tedious in most cases.
The correct way of defining the contentSize in iOS is to define AutoLayout constraints in your View. Here is an excellent tutorial on doing just that:
https://www.natashatherobot.com/ios-autolayout-scrollview/

Vertical View Pager either in Swift or in Objective C

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.

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

Resources