Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook app-style photo zooming from UITableView / Feed

In the Facebook app, when you're on the feed, and you tap on a photo to view it, a few things happen:

  1. The image animates/moves to the center of the screen, no matter where its current position in the table view (middle, partially off the screen towards the bottom, top, whatever)

  2. As the image moves to the center of the screen, the rest of the table view is faded out (alpha = 0)

  3. When you drag the image up or down, the alpha of the table view is restored proportionally (I think) to the offset of the image from the center of the screen

  4. At this point you'll notice that in the Feed, the place where the image used to be, is now empty (giving you the impression that you 'brought' that image up front). You see this by dragging the image up/down and you can see the Feed/table view behind the image.

  5. Following #2, if the image is already proportional (that is, the image's preview on the Feed/table view was a proportionally-scaled one without any cropping) then it just moves to the center. If the image was cropped at all (because it was too tall, etc to fit properly in the Feed) then the rest of the image is revealed at the same time that it is moved to the center of the screen.

  6. Once the image moves to the center of the screen, the gallery view controller elements show up (Done button, Like/Comment buttons, etc)

  7. Following #4, if you swipe to another image (swipe left/right in the full-screen image view to another image in the same album), and then attempt the drag up/down in #3, you'll see that the first image is back to where it was in the Feed.

  8. Finally, if you drag the image up/down past a certain threshold, it is dismissed and the Feed is revealed again.

This is what I think is happening conceptually, and I'd like some confirmation if this is the right approach (these bullets below don't map to the bullets above):

  1. When user taps on an image, add that imageView as a subview of the table view's container view, but add it at the exact same position so that the movement of the imageView from the cell into the main view is not seen.

  2. Then animate the movement of that image to the center of the screen. At the same time, reduce the alpha of the table view so that it reaches 0 at the same time that the imageView reaches the center of the screen.

  3. Once the image reaches the center of the screen, push a modal view controller without animating it, and add the imageView as a subview of the modal view controller's view (effect #6 above)

  4. Any dragging of the image reduces the alpha of the modal view controller and increases the alpha of the Feed table view (effect #3 above) and dragging above a certain threshold triggers the animation that hides the gallery and shows the Feed again (effect #8 above)

Questions:

  1. Am I on the right track? If so, how do I bring the imageView from the cell into the front view - and keep it at that very same position?

  2. When you swipe to another image, the original image is 'restored' into its original location in the cell of the table view. Is this actually just moving one imageView from one view to the next? How the heck do you send it back to the original cell - keep a pointer to that cell when the user taps on the image, and then do something like customCell.imageViewContainerView addSubview:originalImageView? This then needs to be reversed if the user swipes back to the original image?

This whole thing to me seems like a non-trivial implementation, but I think the effect is awesome and I'm also damn curious as to how it's done. Am I overthinking it and there's actually a really easy way to do it, or am I right to give props to whoever wrote the FB app?

like image 839
Jai Govindani Avatar asked Mar 29 '13 13:03

Jai Govindani


1 Answers

Am I on the right track? If so, how do I bring the imageView from the cell into the front view - and keep it at that very same position?

I think that you are right on the conceptual steps. It's not difficult to get the imageView from the cell and add it to the controllers view. You can use the methods like

- (CGRect)convertRect:(CGRect)rect toView:(UIView *)view 

to get the correct position for the imageview.

When you swipe to another image, the original image is 'restored' into its original location in the cell of the table view. Is this actually just moving one imageView from one view to the next? How the heck do you send it back to the original cell - keep a pointer to that cell when the user taps on the image, and then do something like customCell.imageViewContainerView addSubview:originalImageView? This then needs to be reversed if the user swipes back to the original image?

I think that this is made by some kind of protocol between the gallery and the table view controllers. Maybe it just hide/show the image, and the images in the gallery are actually a different object. Anyway, if you want to use the same imageview, you can send the object with the protocol between the two controllers.

Hope this helps a little ;) I think that key is in the convertRect methods.

like image 136
alejandromp Avatar answered Sep 23 '22 15:09

alejandromp