Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

gbf.sara

macrumors newbie
Original poster
May 30, 2010
5
0
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:mad:"%@_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..
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.