Russell Broadbent

Yorkshire based web developer

iOS 4 – Pan Gesture Control

To add a Pan Gesture Controller to an object simply click and drag the Pan Gesture object from the library and drop it onto the object you would like to control (eg. UIImageView).
Next in your class header file add

-(IBAction){method_name}:(UIPanGestureRecognizer *){var_name};

Then in your implementation file add

-(IBAction){method_name}:(UIPanGestureRecognizer *){var_name}
{
    CGPoint translation = [{var_name} translationInView:self.view];
    {var_name}.view.center =
CGPointMake({var_name}.view.center.x + translation.x, {var_name}.view.center.y + translation.y);
    [{var_name} setTranslation:CGPointMake(0, 0) inView:self.view];

}

Once you have implemented the above code simple connect your View’s Received Actions to your Pan Gesture Controller

Comments are closed.