iphoneanimationuibuttoncore-animationpressure

Play & animate with UIButton?


I am doing some RnD work, looking forward for experts suggestion:

I have to create a custom Button with any defined background image. So that user can throw that button in any direction with smooth way, under which total covered distance is directly proportional to pressure applied on UIButton to throw it.

Can any one guide me so that i can cover this task ?


Solution

  • A good start would be to attach a UIPanGestureRecognizer to your button (or view or whatever), then use velocityInView:. From UIPanGestureRecognizer.h:

    // velocity of the pan in pixels/second in the coordinate system of the specified view
    - (CGPoint)velocityInView:(UIView *)view;
    

    Using the velocity (possibly in conjunction with translationInView:) you can then move your button according to the speed and velocity of the gesture.