How do I create a horizontal scroll view with unlimited pages? - ios

I am trying to make an app that you can scroll through and it displays a different string on each page. I though I should use scroll views as they seem to be how I can do this. An example of what I want is UberFacts app. This app you can scroll along and it has a different fact each time. This is obviously not just thousands of different view controllers that are linked by the page control. How do I make view controllers work like UberFacts?
Thanks!

UberFacts seem to use a paginated ScrollView and each page looks like a vertical ScrollView also (you can see by the bounce). But is just one ViewController that manage all those pages.

Related

Creating a menu in iOS

I'm currently creating an update of my iOS application and I'm a bit stuck. I've tried to googling around but cannot find a decent answer on this.
I've a menu which links to different views. And I'm not really sure if I've done it the best method.
I've created a view, and added the links into a stack view. Should I considering changing it all to a tableview? or a collection view? Or maybe there's another way?
The current look:
Should I change this to a tableview? collection view? or something else? Or just let it stay as it is?
If the number of items in your menu changes at runtime and is large, you should use a table view, because a table view is good for efficiently displaying a screen's worth of items from a large list of items.
If the contents of your menu is small (under maybe two screenfuls of items) and fixed at compile time and you are using a storyboard, then you could use a table view with static cells, if you can make it look the way you want.
If the contents of your menu is small, then you can use a stack view (inside a scroll view) if that is easier for you. There is no particular advantage to using a table view over a stack view to display a small amount of content, unless you need other features of the table view (like the ability to select/deselect rows).
Based on the screen shot you posted, I'd either use a table view with static cells (since the screen shot is from a storyboard) or a stack view, depending on whether I can get the appearance I want from a table view. If, as in the screen shot, the buttons must be centered vertically, I'd use a stack view, because it's easier to vertically center the content with a stack view.
Look, the fact of have many itens on your screen is clear on the mobile applications, to make it easy, we have collecions view like UITableView and UICollectionView. On the UITableView's case, this implements the scrolling and have methods do handle the operations' list, you can see the documentation to check these methods: https://developer.apple.com/documentation/uikit/uitableview.
Main reasons to use UITableView
Implements scroll behavior.
Independent of size screen you can access all itens.
Easy to detect interactions like tap on cell.
Easy to make changes, like insert and remove content.
The UITableView exists precisely to solve problems like you has.

UICollectionView vs UIPageViewController

I need to have different full screen views in my app. Very similar to how snapchat works. The views should be able to communicate between each other.
My question is: Should I use a UICollectionView with cells same size as the screen or should I use UIPageViewController?
Please provide some background info to support your opinion!
I think both have pretty different purposes.
UICollectionView is great to build a mosaic of views (think an image gallery for instance), whereas UIPageViewController is kind of similar to the flipping pages of a book. The latter seems to be what you need, but UIPVC doesn't seem to offer many tweaking/customizations, like custom transitions for example. In which case you may want to start from a UIScrollView with paging enabled to recreate something similar but with more potential. Here's an example.
Personal opinion: for this specific case I'd use a page view controller. Collection views have any things you have to consider, like when the device rotates you have to recalculate where you are, which cell you have to display, ask to scroll to the current cell, and if you are displaying a video or using the camera you might have to control it perfectly, otherwise issues will come.
However think about new features that might be added to your app, if you think you might show more than 2 items on screen, then you'd better choose a collection view.
A page view controller lets the user navigate between pages of
content, where each page is managed by its own view controller object.
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIPageViewControllerClassReferenceClassRef/
So If you plan to swipe from one ViewController to another, go for PageViewController. If you plan to have only one ViewController that deal with a list of fullscreen image or so, go for a view controller with a collectionView, or maybe your own swipeView.
UIPageViewController use different view controller and load multiple controller so obvisioly take more memory as compared to UICollectionView. So if your required task is less calculation or step to do then its recommended to use UICollectionView, other case preferred way is to user UIPageController.

UIPageViewController cache and swap view hierarchy for pages with similar content

My UIViewController has a UIPageViewController embedded in it. The pager can contain anywhere from 5-38 pages (each page is an instance of a UIViewController subclass) depending on the situation. I've noticed that depending how complicated I make the UI elements on each page, the app slows down considerably, and is very slow when swiping to go to the next page.
Here's the thing - the view on each page is identical, except for the values of a few UITextViews. I am building the view in each page's viewDidLoad method each time viewControllerAtIndex is called for a new page. I feel like there must be a way to re-use the same view for each page, and just swap the text values that are supposed to be different. Can anyone describe a strategy to do this?
Like I said, every page has an identical view hierarchy except the values for some of the text, so I'm really just looking for a way to maintain one basic view controller per page, but cache the view hierarchy to be re-used on each page, and swap out some simple text values depending on page number.
EDIT
Something I forgot to mention in the original post is that I'm building my view programmatically because the number of elements on the page is dependent on choices the user made on previous screens. i.e. there may be 5 TextViews or 10 TextViews, etc. depending on what the user selected on a previous screen (before coming to the UIPageViewController). With that said, I do not believe an xib based approach will work because the initial layout is dynamic.
Thanks in advance!
Have you tried using a xib based view, which you could pull out of the xib once, and keep a strong reference to it. In your controller's viewDidLoad, you could set its view to this xib base view, then populate the text view(s) with the proper text.

Multiple Visible Pages in Scroll Style UIPageViewController

So what I'm looking to do is have a UIPageViewController that will end up displaying three view controller vies, one fully visible and then two as previews to the right and left. An example would be the iOS6 App Store:
Is doing this using a UIPageViewController set to UIPageViewControllerTransitionStyleScroll possible?
Basically I'd ideally like to have is a case where I can have three UIViewControllers that I recycle as the user pages through the 1- items in the list (with n being at least 50). I know an interface that behaves like this can be done with a UIScrollView with paging enable, but re-using views would take some view shuffling code that I'd rather not write if Apple has already done it for me.
I'm totally comfortable with the fact that this is iOS6 only, by the way, and also comfortable with alternatives, if they exist.
Thanks!
Check the new collection view. I think you may be able to create something like that with reusing cell etc.

iOS: How to get swipe effect between views of tabbed view controller?

I keep seeing apps that appear to be tabbed view controller apps, where the user can easily swipe left or right between views.
How do I enable that kind of behavior?
Thanks.
The best and least hassle free solution I found is Andrey Tarantsov's ATPagingViev class. Works just like a UITableView, i.e. how many pages do you want, scroll horiz or vert. provide view for page, etc. Very easy and well coded. It's here: SoloComponents
It also has a recycling feature so it's memory stable.
If you refer to something like Apples photo app, it is using UIScrollView which has a property to enable paging.
If you define the views content width wider than your view's frame, you'll get the effect you describe. The view will page in steps of it's bounds width.
On each page you can place another view.
http://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UIScrollView_Class/Reference/UIScrollView.html
Another option I found is SwipeView:
https://github.com/nicklockwood/SwipeView

Resources