moving a uiimageview only when touched

Discussion in 'iOS Programming' started by kingsapo, Jul 30, 2010.

  1. kingsapo macrumors member

    Jun 10, 2010
    Hello all! Alright, so my problem is I am trying to make a simple app that will allow the user to touch and drag a picture of a fan (named fan). As of now, the app will have the fan picture follow a finger, even if the touch did not begin on the fan. I wanted the program to need the user to begin the touch on the fan image, and otherwise have it do nothing. Code is posted below, and any help is appreciated!

    @implementation Drag_3ViewController

    -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInView:touch.view.superview];

    if (CGRectContainsPoint(touch.view.frame, location)) { = location;

  2. vocaro macrumors regular

    Mar 5, 2004
    Why not just put the UIImageView in a UIScrollView?
  3. kingsapo thread starter macrumors member

    Jun 10, 2010
    hey, thanks for the response! I actually posted this on Apple's developer forums, and the answer the person gave was good and detailed, though my knowledge of Objective-C is somewhat limited, so I didn't get most of it. So thanks again for your response, and I'll definitely come back to this answer once I hit my Objective-C book again.

Share This Page