I created a view and a scrollview. They both have images inside their view. I'd like to implement a method which makes it possible for the user to drag images in and out of the scroller.
I implemented a UITaprecognizer within my project however I'm not sure how to implement the next steps in my code.
like:
* how to see which image is doubletapped.
* how to make sure that only the doubletapped image is draggable.
* how to drag my image inside or outside a scrollview. (by means of a CGIntersectRect) wich replaces my image in the scroller to the image within my view.
Here's a snippit from my code
Code:
- (void)viewDidLoad{
UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
tap.numberOfTapsRequired = 2;
[image1 addGestureRecognizer:tap];
[image2 addGestureRecognizer:tap];
[image3 addGestureRecognizer:tap];
[scroller addGestureRecognizer:tap];
[self.view addGestureRecognizer:tap];
[tap release];
[super viewDidLoad];
}
-(IBAction)handleDoubleTap:(UITapGestureRecognizer *)recognizer {
NSLog(@"an image is doubletapped");
}
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *) event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:self.view];
if ([touch view] == image1) {
image1.center = location;
}
if ([touch view] == image2) {
image2.center = location;
}
if ([touch view] == image3) {
image3.center = location;
}
[self checkcollision];
}
-(void)checkcollision {
//check collision here
}
Help is greatly appreciated!