2

There is this great ui guide which shows some cool ui transitions.

I would like to know how to do this animation (the great one). enter image description here

I know how to do the good one. I also have some success with the great one (by taking snapshot of the next viewcontroller to be presented and expanding it inside animateTransition(using transitionContext: UIViewControllerContextTransitioning)).

However I do not know how the great one pushes it's adjecent views on both sides.

I would like get an idea on how to do exactly that(push out). I do not need code. Just a general guide is fine.

EDIT: I ended up implementing Kubba's idea.

trungduc's idea of animating tableview cell height has some drawbacks. The cell position is not proper before and after transition. Also, syncing the animation of viewcontroller frame with tableview cell height proved to be futile. Nevertheless it was a good solution although perhaps for a slightly different problem.

Project

Rishab
  • 1,901
  • 2
  • 18
  • 34

3 Answers3

3

I'd try something like this:

  • take a snapshot of current controller
  • extract two pieces from it: (1) from top of the card to top of the screen and (2) from the bottom of the card to bottom of the screen
  • place them in places where they should be
  • move (1) tho the top and (2) to the bottom along with your current transition

Another idea, which could be easier to achieve: you can just divide the snapshot on two pieces in the middle of expanding card but I'm not sure how animation would behave

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Kubba
  • 3,390
  • 19
  • 34
2

My solution is quite simple without snapshots.

  1. When tapping on cell, save tableView.contentOffset.
  2. Increase height of selected cell to screen height.
  3. Update cell height, move cell to top of screen with an animation and pushing transition.
  4. When you want to come back, decrease height of selected cell, change contentOffset by cached value with animation and transition.

Result.

enter link description here

I use the below code to make animation for tableView, put it inside didSelectRowAtIndexPath method.

[UIView beginAnimations:@"animation" context:nil];
[UIView setAnimationDuration:4.f];
[CATransaction begin];
[tableView beginUpdates];
[tableView endUpdates];
[tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
[CATransaction commit];
[UIView commitAnimations];

Sorry I'm not good at Swift ;)

trungduc
  • 11,926
  • 4
  • 31
  • 55
  • No need to be sorry. That's quite a trick you have implemented. Really good except in my project I need to go to a view controller. But this did give me a new angle. – Rishab Mar 22 '18 at 12:54
  • Seem like you didn't understand my answer totally. My answer is used to push a new view controller. That's why I always say **animation and transition**. I mean pushing new view controller transition and **come back** means dismiss view controller. – trungduc Mar 22 '18 at 13:57
  • As I understand, your question is about pushing adjecent views on both sides and you know how to implement `animateTransition` method to push new view controller. That's why my demo just display how animation works on tableView. If you need my help to finish it, tell me. But I think with my guide, you can implement it yourself ;) – trungduc Mar 22 '18 at 13:59
  • I am working with your given solution. That's why I said I got a new angle. Thanks for the clarification though. – Rishab Mar 22 '18 at 14:10
  • Good luck. Hope I can see the result after you finish it. – trungduc Mar 22 '18 at 14:18
  • One more, taking snapshot of the next view controller to be presented somehow will affect performance. In my opinion, you just need to give next view controller a suitable layout for transition. – trungduc Mar 22 '18 at 14:18
  • I have provided a link to my project. – Rishab Mar 27 '18 at 09:59
1

You can use Hero UIViewController based transitions animation library which support many type of animation.

Integration is very simple, to achieve beautiful animation.

You can use below sample screenshot, Which is create using Hero.

enter image description here

Jaydeep Vora
  • 6,085
  • 1
  • 22
  • 40