Customizing / subclassing UICollectionViewLayout to enable scrolling in multiple directions - ios

I'm designing a layout for my app that is going to take advantage of UICollectionView. I have created some moderately complex collectionView-based apps before, but I may need to subclass the layout class for this one. The main point I'm trying to figure out is whether I can have different sections of the same collectionView scroll in different directions.
Based on what I have read and tried so far, the only way to have one section scroll horizontally and another vertically would be by using multiple nested instances of UICollectionView.
This is a basic idea of my layout. My guess is that even with subclassing, a single UICollectionView would not be able to handle it. Or would it?

I think you could do it with a custom UICollectionViewLayout but I'd use the default flow layout with one cell containing something like a SwipeView for the section 0 and other cells in your section 1.

Related

Random UICollectionView grid

I'm about to do my first UICollectionView and from a syntax point of view it looks almost exactly the same as what you would do for a UITableView.
I'm trying to figure out how I could build a photo grid that is based on the image below.
Can this be achieved with a single UICollectionview, or do I need to do a static view for the big images and then two collectionViews beside it (yuck!) or can this be done with sections?
This can be achieved using a single collection view. You can customize your collection view using UICollectionViewLayout. UICollectionViewLayout is very powerful, and you can achieve almost every kind of layout with this. Here's a very in-depth tutorial explaining the UICollectionViewLayout. Understand it and change it to according to your needs.
Link

Vertical CollectionView inside an horizontal CollectionView Swift iOs

I am an Android dev trying to learn iOs development.
I am trying to implement a vertical scrolling UI inside an horizontal paging scroller (Like a RecyclerView inside a ViewPager).
I know I should use nested UICollectionView, I saw this tutorial doing similar stuff, however, it uses UITableView to create the reversed layout style (Horizontal scroll inside vertical scroll).
Can you tell me the best practice to implement this kind of layout? Is there any tutorial out there? I wasn't able to find really much (most stuff was regarding the reversed layout)
Thanks
edited:
1: if you want couple main pages you should implement uipageviewcontroller, to be able paging horizontally
2: if you want a lot reusable cells paging horizontally you should implement UICollectionViewController
if you need vertical scroll functionality inside every page/cells depends if you want paging/scrolling with many cells (you should use collection view) or scrolling some content like text or so (you want to use scrollview). And then you need to put UICollectionView/UIScrollView as a subview on your pages(uipageviewcontroller) / cells(collectionView)
btw. adding vertical scrolling if you need collectionviewcontroller would be bad idea, because you'd have many scrollviews within many cells

UICollectionView layout with custom layout

Is it possible to create a collection view with an item on the left and two items stacked to the right of it?
Whenever I specify the correct sizes to do this in the sizeForItemAtIndexPath delegate I can only get one item on the right side and the other is displayed in the next row underneath. I know I can do this with custom cells that contain more than one view (top and bottom) but I would like to know if its possible without that. It would be a lot less complex if I could do it without the custom double view cell. Im using a 'flow' layout with 'vertical' scroll direction (as per IB).
First image is what I hope to achieve and the second is what I am able to achieve currently.
You need to implement custom UICollectionViewFlowLayout subclass for this - Creating Custom Layouts

iOS: CollectionView stick header while scrolling

I am implementing CollectionView with custom layout. It have vertical scrolling.
I want to make that some cells will be sticked to the top while scrolling like section header in tableView.
The idea is to create day collectionView with time. And while user will be scroll thought time the current hour will be sticked to the top(if it will be not visible and hidden by top). It will be only if the current hour hidden by top, not by bottom. And the other items should be scrollable like usual.
I think that I should not use supplementaryViews here
Is it possible and how can I do it?
You need to override shouldInvalidateLayoutForBoundsChange so it returns YES. This means layoutAttributesForSupplementaryViewOfKind and layoutAttributesForElementsInRect are called when the UICollectionView is scrolled, and in there you can then calculate proper frames for your views, including the sticky views. If you have a complicated UICollectionView, this may lead to bad performance, but as far as I know it's the easiest way to do this for now. Your other bet is looking at invalidation contexts, but they're quite badly documented. If you still want to experiment with those, you could take a look at Using Invalidation Contexts for UICollectionViewLayout
Take a look at UICollectionView's supplementaryView.
Apple's Collection View Programming Guide

iOS UICollectionView inside UITableViewCell

I want to implement a list containing several images grouped together like in the following mockup. The number of images to display in each section is dynamic and may vary. I also all images in a section to be always visible (without having to scroll horizontally or vertically).
What is the best approach to achieve this? I was making some tests with UICollectionView inside UITableViewCell but I can't make UICollectionView/UITableViewCell size expand automatically depending on the number of images inside.
Is UICollectionView/UITableViewCell the way to go or is there a simpler approach?
You don't need the UITableView to achieve this, here is the link for the implementation of Sticky Header for the UICollectionView.
https://gist.github.com/evadne/4544569
You need to implement collectionView delegate and dataSource methods inside uitableViewCell. Look it:https://contentpedlar.wordpress.com/2016/10/22/uicollectionview-in-uitableview/
This in Swift, but you easy understand it in Objective-c

Resources