Tinder like pan iOS

后端 未结 5 909
刺人心
刺人心 2021-01-22 23:24

For the Tinder app in iOS, I assume they are using a pan gesture recognizer on the image view. How is it that another image is shown underneath the image the user has started to

5条回答
  •  半阙折子戏
    2021-01-23 00:01

    I just implemented this recently for the company I work for and decided to open source it. https://github.com/skensell/MXCardsSwipingView

    I used UIKit Dynamics, in particular the UIAttachmentBehavior. So when someone pans I create a new attachment behavior (essentially attaching their finger to that part of the card) and add it to a UIDynamicAnimator. When they release their finger I move the anchor point of the attachment off screen in the same direction as the end velocity (resulting in a smooth dismissal animation) and then after 1 second I remove it from the view hierarchy.

    Internally I maintain a queue of the cards and whenever a pan starts I attach to the topmost card.

    More details here: https://github.com/skensell/MXCardsSwipingView/blob/master/MXCardsSwipingView/Classes/MXCardsSwipingView.m

提交回复
热议问题