如何在多个UIViews或UIImageViews上使用UIGestureRecognizers进行点击,捏合和旋转

时间:2013-05-13 12:54:56

标签: iphone ios objective-c image-processing uigesturerecognizer

我不知道如何处理: - /

我只需要在图像上添加贴纸。应用程序将在选择特定贴纸时贴上像表情符号,心(图像)的贴纸,它将被添加到主图像中,用户可以使用贴纸进行操作,如旋转,缩放等,用户可以选择多个贴纸并可以进行旋转缩放等添加贴纸,

请指导如何实现这一点,我能够用单个贴纸执行图像制作我不知道如何进行多个贴纸选择,用户可以再次回到任何贴纸并对其进行操作。

2 个答案:

答案 0 :(得分:5)

您可以使用此方法添加手势:

- (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];
}

并实现这些选择器:

- (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");
}

注意:根据需要更改值

答案 1 :(得分:0)

我希望您在图像视图中添加手势,当您单击特定图像时,您想对该特定图像执行某些操作,然后尝试这样可能会帮助您

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
}

添加此项以进行同步手势识别。

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
return YES:
}