PDA

View Full Version : moving a uiimageview only when touched




kingsapo
Jul 31, 2010, 12:33 AM
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)) {
fan.center = location;
}

}



vocaro
Aug 3, 2010, 06:49 PM
Why not just put the UIImageView in a UIScrollView?

kingsapo
Aug 4, 2010, 05:35 PM
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.