I've got a scroller within my view and got several images inside this scroller.
I'd like to drag and drop these images out (and into) my scroller. I implemented a LongPressGestureRecognizer.
I also would like to know (by code) which image got longpressed. I thought I fixed this last one by using CGRectContainsPoint. However my code is not reacting to the CGRectContainsPoint. It still Logs "fail".
- (void)viewDidLoad{
//scroller properties
scroller.contentSize = CGSizeMake(1300, 130);
scroller.scrollEnabled = YES;
scroller.directionalLockEnabled =YES;
scroller.frame = CGRectMake(0, 874, 768, 130);
UILongPressGestureRecognizer *longPress =
[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressed:)];
[image1 addGestureRecognizer:longPress];
[image2 addGestureRecognizer:longPress];
[image3 addGestureRecognizer:longPress];
[longPress release];
}
-(void)longPressed:(UILongPressGestureRecognizer *)sender {
CGPoint location = [sender locationInView:self.view];
if(CGRectContainsPoint(image1.frame, location)) {
NSLog(@"image1 has been longpressed");
// do something
}
if(CGRectContainsPoint(image2.frame, location)) {
NSLog(@"image2 has been longpressed");
// do something
}
if(CGRectContainsPoint(image3.frame, location)) {
NSLog(@"image3 has been longpressed");
// do something
}
else {
NSLog(@"fail");
}
Has someone got experience with this LongPressGestureRecognizer and the number of images that can respond to this function?
i did succeeded implementing the two gesturerecognizers. So the images within my scroller are now draggable. However it limits itself inside the scrollview. I'd like to have some function which takes care of bringing the images in front of the scrollview, so that I can drag my images out of my scrollview.
Within my viewDidLoad method I implemented
[scroller addSubview:image1];
[scroller addSubview:image2];
[scroller addSubview:image3];
[[self view] addSubview:scroller];
and within my longPressed method I implemented
[image1 bringSubviewToFront:self.view];
Someone has good Tips? They are greatly appreciated!