How to move/drag multiple images with CALayer???
Posted
by gbf.sara
on Stack Overflow
See other posts from Stack Overflow
or by gbf.sara
Published on 2010-06-03T06:39:15Z
Indexed on
2010/06/03
6:44 UTC
Read the original article
Hit count: 344
calayer
I have more than 10 images in screen and i want to move each image using CALayer concept. While am trying to move first image,its working. Even when i drag my second image also, its working. But after that when i get back to first image and when i try to move , am struck up. its not working. I dono where it went wrong. Here's ma code
//Assigning Layer to UIImage// layer = [CALayer layer]; UIImage *image1 = [UIImage imageNamed:[NSString stringWithFormat:@"%@_thumb.png",[tiv imageName]]]; layer.contents = (id)image1.CGImage; layer.position=CGPointMake(200,200); layer.frame = CGRectMake(110, 180, 100, 100); [self.view.layer addSublayer:layer]; [layer needsDisplay]; [self.view.layer needsDisplay]; [layer needsLayout];
//Here i try to move my image// - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesMoved:touches withEvent:event]; NSArray *allTouches = [touches allObjects]; int count = [allTouches count];
if (count == 1) {
if (CGRectContainsPoint([layer frame], [[allTouches objectAtIndex:0] locationInView:self.view])) {
layer.position = [[allTouches objectAtIndex:0] locationInView:self.view];
return;
} }
if (count > 1) {
if (CGRectContainsPoint([layer frame], [[allTouches objectAtIndex:-1] locationInView:self.view])) {
layer.position = [[allTouches objectAtIndex:0] locationInView:self.view];
return;
}
}
}
Also ive planned to use single CALayer for multiple images.. When i click an image, it should be placed in that CALayer and when i click another, the same CALayer should take the latter one. So tat whenever i drag an image it should move(no matter how many images r there) . Do u think this concept will work out or is there any other idea???
My concept may seems to be a basic one. Am new to this environment n so kindly help me..
© Stack Overflow or respective owner