-1

How do we create a bounce effect when user touch a UIView?

  1. User touch and hold the view, the view shrink in size.
  2. When user release it, it pops back and bounce to it's normal size.

I have no idea how to explain this. But i would say It's like the one on the Tinder user's picture when it's pressed..

JayVDiyk
  • 4,277
  • 22
  • 70
  • 135

2 Answers2

0

To have that effect you can you can use UIKit Dynamics and here is a sample code provided by Apple itself. You can use UIDynamicAnimator and UIAttachmentBehavior to achieve what you want.

You can also use UIControlEventTouchDown and UIControlEventTouchUpInside event of UIButton to handle this case, if not UIDynamicBehavior.

Thanks, hope this helps.

Pradeep Singh
  • 752
  • 1
  • 10
  • 23
0

For handling the touch gesture i would suggest adding a Long Press Gesture Recogniser to the view in question. Control drag to create a function like this

@IBAction func longPress(sender: AnyObject)
    {
        if sender.state == UIGestureRecognizerState.Began
        {
            //Shrink animation
        }               
        else if sender.state == UIGestureRecognizerState.Ended
        {
            //Bounce animation
        }
    }

I'm not that familiair with creating my own animations, but I have used this library called Spring (https://github.com/MengTo/Spring) in the past which was really easy to install and use to add good looking animations.

TheNiers
  • 237
  • 2
  • 4
  • 15