2

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 ?

Tariq
  • 9,861
  • 12
  • 62
  • 103

1 Answers1

2

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.

Domestic Cat
  • 1,434
  • 11
  • 18
  • Great :).. That i was looking for – Tariq Jul 05 '11 at 06:05
  • Hey now I am able to throw Button with defined velocity. Now can you please tell me. How can I add 5 images in to that button ? So that when I throw Button only button image changes upto image1 to image5.. and button image should be 5 when throw animation stop. I am trying with UIImageView startAnimating but it keep running on.. and not synced with PanGesture also – Tariq Jul 05 '11 at 06:37
  • http://stackoverflow.com/questions/6578795/how-to-sync-uipangesturerecognizer-with-uibutton-5-images – Tariq Jul 05 '11 at 06:42