Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

enter image description here

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...

like image 777
Dănuț Mihai Florian Avatar asked Nov 27 '13 18:11

Dănuț Mihai Florian


2 Answers

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.

like image 182
Andy Poes Avatar answered Oct 11 '22 01:10

Andy Poes


It's very cool! We made a fairly simple to use control like this that can be found here:

https://github.com/RobotsAndPencils/RPSlidingMenu

like image 22
Codezy Avatar answered Oct 11 '22 03:10

Codezy