The following lines of code represents objects that i insert into a scrollView.
My problem is, none of the images inside the scrollview are drag-and-droppable.
When the images are added alone, that is outside the scrollview, they are perfectly click - and drag-and-droppable.
It appears every event that occur triggers the scrollViews listener, and not the clicked image listener.
The scrollView is perfectly scrollable regardless of how the images are added.
How can i trigger the image drag-and-drop if clicked, and still be able to scroll it's parent view - the scrollView?
#import "BookShelfSection.h"
@implementation BookShelfSection
- (id)initBookShelfWithX:(CGFloat)x y:(CGFloat)y width:(CGFloat)width height:(CGFloat)height
{
self = [super initWithFrame:CGRectMake(x, y, width, height)];
self.userInteractionEnabled = YES;
return self;
}
- (void)addPages:(NSArray *)fileNameArray
{
for (id shelf in fileNameArray) {
UIView *view = [[UIView alloc] initWithFrame: CGRectMake ( 0, 0, self.frame.size.width, self.frame.size.height)];
UIImage *image = [UIImage imageNamed:[NSString stringWithString:shelf]];
UIImageView *page = [[UIImageView alloc] initWithImage:image];
page.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
page.contentMode = UIViewContentModeBottom;
UIImage *image2 = [UIImage imageNamed:@"car_1.png"];
Item *item = [[Item alloc] initWithImage:image2 andPosition:CGPointMake(100, 100)];
page.userInteractionEnabled = YES;
item.userInteractionEnabled = YES;
[view addSubview:page];
[view addSubview:item];
[self addPageView:view];
}
}
@end
EDIT: This is how i perform my drag and drop: The Item Class:
#import "Item.h"
@implementation Item
- (id)initWithImage:(UIImage *)image andPosition:(CGPoint)position
{
CGRect cellRectangle = CGRectMake(position.x, position.y,image.size.width ,image.size.height );
self = [[Item alloc] initWithFrame:cellRectangle];
if (self) {
[self setImage:image];
[self setUserInteractionEnabled:YES];
}
return self;
}
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint pt = [[touches anyObject] locationInView:self];
startLocation = pt;
[[self superview] bringSubviewToFront:self];
}
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint pt = [[touches anyObject] locationInView:self];
CGRect frame = [self frame];
frame.origin.x += pt.x - startLocation.x;
frame.origin.y += pt.y - startLocation.y;
[self setFrame:frame];
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
CGRect frame = [self frame];
int originX = (int)roundf(frame.origin.x);
int originY = (int)roundf(frame.origin.y);
NSLog(@"Touch ended at point: [%d, %d]", originX, originY);
}
- (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"Touch cancelled");
}
@end