Question

I don;t know how to handle this :-/

I just need to add stickers on an image. App will conatins stickers like smilies, hearts (images) on selecting the particular sticker it will be added to main image and user can manipulate with sticker, Like he rotate, scale etc, User can select multiple stickers and can do rotation scaling etc with added stickers,

please guide how to achieve this, I able to perform image maniuplation with single sticker i dont how to perform it for multiple stickers selection, User can again come back to any sticker and perform operation on that.

Was it helpful?

Solution

You can add gestures using this method:

- (void) addGestureRecognizers{
    UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
    [panRecognizer setMinimumNumberOfTouches:1];
    [panRecognizer setMaximumNumberOfTouches:1];
    [self addGestureRecognizer:panRecognizer];

    UIRotationGestureRecognizer *rotateRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];
    self.multipleTouchEnabled = YES;
    [self addGestureRecognizer:rotateRecognizer];

    UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinch:)];
    [self addGestureRecognizer:pinchRecognizer];

    UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressed:)];
    longPressRecognizer.minimumPressDuration = 2.0;
    [self addGestureRecognizer:longPressRecognizer];
}

and implement those selectors:

- (void) move:(UIPanGestureRecognizer *)recognizer{
    CGPoint translation = [recognizer translationInView:self.superview];
    recognizer.view.center = CGPointMake(recognizer.view.center.x+translation.x, recognizer.view.center.y+translation.y);
    [recognizer setTranslation:CGPointMake(0, 0) inView:self.superview];
}

- (void) rotate:(UIRotationGestureRecognizer *)recognizer{
    NSLog(@"Rotate");
    recognizer.view.transform = CGAffineTransformRotate(
                                                        recognizer.view.transform,
                                                        recognizer.rotation);
    recognizer.rotation = 0;
}

- (void) pinch:(UIPinchGestureRecognizer *)recognizer{
    recognizer.view.transform = CGAffineTransformScale(recognizer.view.transform, recognizer.scale, recognizer.scale);
    recognizer.scale = 1; 
}

- (void) longPressed:(UILongPressGestureRecognizer *)recognizer{
    NSLog(@"Long Pressed");
}

NOTE: Change values as you want

OTHER TIPS

i'm expecting you are adding gestures to image view when you click on particuler image you want to perform some action on that particuler image right ,then try like this may be it'l helps you

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTapped:)];

...

- (void)imageTapped:(UITapGestureRecognizer *)sender
{
    UIView *selectedView = sender.view; 
    //perform action here

    or

  sender.view.frame=newFrame;//you can set your frame
}

add this one for Simultaneous gesture recognization.

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
return YES:
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top