How can I stack cells (in a UICollectionView) on top of each other? Feedly does it quiet well and I was wondering if I can somehow manipulate the zIndex property to get a similar effect in navigation of a UICollectionView.
Or am I wasting my time with UICollectionViews and should be looking into changing my approach with perhaps a Container View Controller?
In order to accomplish this my team added a basic full page horizontal cover flow layout to a uicollectionview. We then added a pan gesture recognizer and disabled scrolling on the collectionView controller. As soon as the pan gesture starts we screen cap the cell and place the image over the collectionView. Once that is done we manually change the page of the collectionView to the next page behind the screenshot. We then animate the uiimage (the screen cap of the previous page) along the path of the gesture. If it goes past a threshold we commit the animation and remove the image and you get the full effect of a previewed collectionView cell.
Unfortunately the threshold checking is a bit tedious because you must revert. Also the animation for bringing a cell back is a little quirky. With this method if you don't add it as a special case then it looks the cell is always behind. Since we want it to look like a stack we made sure that it looks like you are pulling the previous cell from offscreen to the top of the stack. This is done by keeping a collection (NSArray) of cell screenshots that matches are data source so basically we can just grab the image based on indexPath.row. Do the pan gesture recognizer to bring it back on to the stack. If it passes the threshold we commit the animation and at the end change the current cell of the collection view and remove the screenshot. So it feels seamless.
There is really nice write up regarding this, jump onto this website and you will find everything you need.
http://skeuo.com/uicollectionview-custom-layout-tutorial
Basically what you are looking for is the CustomLayout.
You can use CHTCollectionViewWaterfallLayout to create pinterest-like-layout. It's created on top of UICollectionView.
Related
I have an iPad app similar to the iPad Keynote with a narrow overview on the left and a paged UICollectionView of my "slides" on the right. The collection view is using the default FlowLayout. Some of these slides are standard PDFs and some are embedded UIViewControllers that have been scaled (with a CGAffineTransform) and embedded in the cell. I'd like to smoothly animate the overview sidebar offscreen and zoom the current page cell to fullscreen. The collection view should allow paged swiping at whatever size. I'm using storyboards and autolayout.
I think I need to simultaneously animate about three things:
The collection view constraints (to the sidebar) to enlarge/shrink it
The flow layout's sizeForItemAt: value
The CGAffineTransform on the embedded view controller.
I have some pieces working (a single embedded View Controller "slide" that scales correctly) but cannot get the collectionView/cell resize dance to work correctly. The cell resize animation is jerky, or ends up with the wrong offset, or works for the leftmost cell but not for other cells.
I've tried most of the suggestions in the answers to this question but with no convincing success. I can't believe it's impossible but at this point I'm considering the smoke and mirrors approach of animating a static slide and hiding it after the animation completes. The attached video - ignoring the glitches - illustrates the kind of effect I'm after:
It's worth noting, on close inspection, that Keynote cheats somewhat when it comes to swiping between slides in edit mode, and manually manages the next slide sliding onscreen, so probably doesn't use a UICollectionView.
Has anyone done anything similar, or have any suggestions for things to try?
I managed to solve this. There's a proof-of-concept GitHub repo here.
There are a few moving parts:
There are two pieces of UIView scaling code. I suspect these could be combined with suitable delegate references as the nested view controllers are embedded. The first piece scales (statically) correctly when the Collection View cell is created. The second is an animated scale/translate when the sidebar size is changed.
I added a FlowLayout subclass to remove flicker as the collection's layout is invalidated during scaling.
The sidebar-related transform in the top-level VC uses most of the tricks in the book - invalidateLayout(), performBatchUpdates(...), layoutIfNeeded() etc. as well as animating the contentOffset to the correct value. Some manual tracking of the correct page/slide is required.
There's still a slight flicker occasionally at the start of resizing. This may not be an issue with my particular colour-scheme which will be black on dark gray. Bonus points if anyone can suggest how to track this down or alleviate it.
I am working on a UICollectionView that reload the cells animatedly.
I have wrote an animation code in my layout class in
- (UICollectionViewLayoutAttributes*)initialLayoutAttributesForAppearingItemAtIndexPath:(NSIndexPath *)itemIndexPath
And its works perfectly i just want to know is that somehow can i introduce an delay in cells animations so it will be like first cell reaches its place than second and then third cell and so far.
So is there any specific way to achieve this?
Unfortunately, the framework is not designed to work in that way. I would not animate the frames directly – that is a dark path that leads to pain. You'd basically need to add one model to the data source backing the collection view, wait, and repeat. It shouldn't be too hard, but it is a bit hacky.
If the appearance animation you'd like to achieve is a frame animation you can adjust the initial start position instead of adding a delay.
Let's say you want your cells to fly in from the right. For the first cell you can set the initial offset to 500px, for the second 600px for the third 700px and so on. Even though they all start animating at the same time, they'll reach their positions in succession.
Hope this helps.
I'm trying to recreate the passbook UI using a collection view with a custom layout.
So far so good, but there's this thing I can't seem to find a solution for.
Problem: When I click on a cell I want it to move up to the top of the screen (content offset of the cv). Most of the cells don't have a problem with this and they perform as such. However, when the selected cell is near the bottom of the screen, there's no moving at all... just a fade-out and fade-in.
To achieve this animation, I embedded the layout subclass' invalidateLayout in an animation block to be performed by UIView. No matter how high or low I set the time interval, the duration is still the same, and so no effect on the fade-in fade-out behaviour.
I'll paste here the methods that I believe to need to be modified and also a link to a video on youtube. Hopefully, someone can find a solution for this >_<".
YT: https://www.youtube.com/watch?v=3xIL-fFUcJo
Code: http://pastebin.com/QKLKGwdN
I have a UIPageViewController which manages UINavigationControllers, which are hooked up to a UITableView. I want the user to be able to swipe between the different "table views", which currently works. When the user swipes on the first or last page, the controller moves off the screen and there is black behind it. I don't want the user to be able to swipe off the screen.
I tried using gesture recognizers to prevent pan and swipe gestures in a certain direction when the user was at the first or last page but when I returned NO in gestureRecognizer:shouldReceiveTouch: the view was still able to scroll.
In the end I am trying to emulate how "snapchat" works, I don't mind using a different method to achieve what they have I just am unsure how I would do it.
You can try setting background color on the superview to white or the color of your tableview.
I finally figured out an easy semi-fix. I decided to take a screenshot and use the clone tool to get rid of all the labels and I set it as the background image of the UIPageView. Now at least it doesn't look black, it just looks like the tableview continues off the screen.
I'm using a UICollectionView (with horizontal layout) to manage a collection of images. The view controller that manages the collection view has the bottom toolbar visible with a play button to start a slideshow of the images in the collection. My question is what is the best way to implement a slideshow that involves a collection view? My initial thought was to try to make the collection view changing the visible cells with a UIView transition (transitionFromView or transitionWithView) with a cross dissolve option but I didn't get the effect I was expecting (maybe something wrong in my code). The other idea I had was to simply add a subview to the collection view to handle slideshow. This subview would have access to the data source and be able to iterate through the images. Don't know if this last option is a good way to approach the problem. Anyone has ever tried this and/or what would the recommendation be to solve this problem?
My idea is no need of collection view. In scrollview place imageview which display images. In timer Change the offset of scrollview. so it looks like automatically images are changing as like slide show.