UICollectionView Full Screen Vertically and 2 Screens Horizontally - ios

I have a UICollectionView that displays one cell at a time that has the size equals to the UIViewController.view.bounds.size. This works great for me on Vertical/Portrait screen.
I want to rotate the screen to landscape and a nice animation happens to show 2 cells side by side each having size equals to CGSize(UIViewController.view.bounds.width / 2, UIViewController.view.bounds.height)
Is there a library that does that or how can I achieve this approach?
You can think of it as an image gallery that displays one image at a time when rotated should show 2 images.

If you are using flow layout, then all you have to do is implement UICollectionViewFlowLayout delegate methods, and invalidate the collectionView's layout on rotation.
Take a look at this repo: dynamic width cells
It's not exactly what you are looking for, but you can get a general idea.

Related

Customising layout change animation on UICollectionViewFlowLayout

I have a UICollectionView that has two layout's (list style like uitableview and gallery style which is a full screen horizontal item scroller).
The cell contains a single image and two labels (title & description). In list layout the image is on the left and labels on the right. In gallery layout the image is full width & 50% height with labels beneath. Like this:
The default animation when switching between these two layouts is too simply resize and move the cells to their new positions in the layout. However I want to make a much more specific animation.
Specifically these are the rough steps I want the animation to take when going from list to gallery view:
Fade out all but the first visible cell (aka cell 1)
Fade out the labels in cell 1
Grow the width of the image in cell 1 to 100%
Grow height of cell 1 to full screen (with the image height following the cell growing - to 40% height)
Fade back in the labels for cell 1
Show the other cells (although they should be off screen - so this may not be neccessary)
The steps would pretty much reverse for gallery -> list layout change.
The UICollectionViewFlowLayout is perfect for the layouts that i want to achieve, I just want to have a much finer control over the animation so that I can produce this "stepped animation" (or would this be like keyframe animation?)
It probably doesn't matter much - but i'm using auto layout constraints (via SnapKit) wherever possible and i'd like to maintain that where i can.
Of course I don't expect someone to program all this for me, however Google isn't helping me work out where to start.
Could someone please point me in the right direction of which methods I need to be implementing/overriding on which classes, and maybe a hint of pseudo-code?

xcode, align 20 images, grid view

Need some help ^_^,
I'm trying to align 20 images together, in the storyboard,
https://www.dropbox.com/s/cnyojn82rn84c9j/pic1.jpg?dl=0
https://www.dropbox.com/s/05u50dd54w756q7/pic2.jpg?dl=0
I need them to look same in the portrait and landscape mode, so if you imagine rotating phone, then 20 pictures rotate 90 degrees, but not the whole view, when view rotates to landscape, bottom row disappears.
Sorry, it's hard to explain =D, basically in portrait top row has 4 pictures, in landscape top row should have 5 pictures.
Would be even better if they would change size of the image depending on the screen size.
Thanks,
Why there is need of 20 images to be designed in storyboard, When we have UICollectionView for that purpose, you never need to worry about the rotation, Collection view will automatically adjust it cells accordingly.
If you need tutorial you can surely go ahead with this link
I suggest you look into UICollection views with a flow layout. It might sound unwieldy at first but it is definitely the best solution for what you want to achieve. Apple documentation can be found here: https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/CollectionViewPGforIOS/CollectionViewPGforIOS.pdf

UICollectionView - a couple of questions

I'm working on an app that is making use of a collecitonview. It's pretty simple as far as the colletionview goes...just displays an array of uiimages in a single-line, horizontal direction view. Here are my questions...
Do I need to have a custom flow layout just to center the images when scrolling? I was able to center the first image the way I want by using insetForSectionAtIndex, however, when I scroll (horizontally), the images are aligned to the left edge of the screen. I was able to fix that by subclassing UICollectionViewFlowLayout and overriding targetContentOffsetForProposedContentOffset. However, I think there has to be a way to do such a simple task without using a custom layout. Also, using this method, while it centers the images when scrolling, it does not allow paging (no snapping the next image in place), which I would prefer. I thought that insetForSectionAtIndex would be called when scrolling through each image, but that does not seem to be the case. Is there any way to force that?
The other question is sort of related to the first...how do I place the cells exactly where I want them? I have the images centered as far as the left and right edges, but I need to move the cells up (- negative) on y axis. Is overriding layoutAttributesForElementsInRect the only way to do this?
Thanks in advance!
In the storyboard, after you add the imageView to the contentView of the cell, use this to center it:
imageView.center = CGPointMake(cell.contentView.bounds.size.width/2,cell.contentView.bounds.size.height/2);

Ultravisual iPhone app like UIView or UITableView scroll

Can someone please give me a hint on how to recreate the scrolling effect used in the UltraVisual iPhone app? Here's a gif to illustrate the effect:
The first "cell" is full height while the other displayed cells are regular sized. While the user scrolls up, the first cell slowly animates to the regular height, while the next one slowly gets bigger. Do they use an UITableView? Or an UIScrollView? I have no idea how it's made...
Ha, you made my day! I actually wrote that view :)
This is actually very straightforward. This view uses UICollectionView with a custom UICollectionViewLayout.
The general principle is this. I make up a 'drag interval' – that is the required distance to drag between each cell. This value is arbitrary but affects how much the user has to drag to switch cells. The total height of the collection view is the 'drag interval' * the number of items in the view. Then I set the layout to automatically paginate to the nearest drag interval (which gives it the snapping behavior). This is very similar to how coverflow works. From this you can calculate the index of the 'top cell' by dividing the contentOffset.y by the height.
With the 'top cell' index you can generate the frames for each cell pretty easily. The top cell's frame is { 0, contentOffset.y, 320, 176 }, and from there you can calculate the next cells frame and so forth.
Then the last trick is calculating the interpolation of the page index. This is basically the decimal part of the current cell index. This will give a number between 0 and 1 that can be used to calculate the interpolation between the top frame and the frame below.
Every 'prepareLayout' calculates the frames of the cells on screen, and then in layoutAttributesForElementsInRect:, generate all the layoutAttributes based on the generated frames.
Using this trick you can create all sorts of complicated layouts. UICollectionView can be a powerful beast, but definitely takes a bit to wrap your head around it.
It's very cool! We made a fairly simple to use control like this that can be found here:
https://github.com/RobotsAndPencils/RPSlidingMenu

Manipulating scroll view in Corona SDK

I have a class with a scroll view that has a width of 980. I also have about 100 buttons aligned 5 columns x 5 rows for each 320 width of my scroll view. The scroll works okay but I'm trying to achieve two things:
Allow scrolling only when slide length is about 50% of screen size
If the slide length is half the screen size, then it would immediately slide/scroll to the next 25 items. For example, in plain sight you would see buttons 1-25 then if you try to scroll, the next 25 objects would be displayed (buttons 26-50).
I followed the sample from here but I don't know how to implement what I want to do or if it's even possible to do this using scroll view. I hope someone can give me a good example or idea. Thanks.
Try something like this: http://developer.coronalabs.com/code/slider-module-springboard-functionality-warning-shameless-promotion-inside. It works sort of like the iOS springboard.

Resources