0

我不使用UIGestureRecognizers用於自來水,捏和旋轉;知道如何處理這個問題: -/如何在多UIViews或UIImageViews的

我只需要在圖像上添加標籤。應用程序將confeins貼紙喜歡錶情符號,心(圖像)選擇特定的貼紙它將被添加到主圖像和用戶可以操縱與貼紙,像他旋轉,縮放等,用戶可以選擇多個貼紙,並可以做旋轉縮放等添加貼紙,

請指導如何實現這一點,我能夠執行圖像maniuplation與單貼紙我不怎麼執行它的多個貼紙選擇,用戶可以再次回到任何貼紙,並執行操作。

+0

你的意思是更改值說你旋轉一個貼紙,並且所有貼紙旋轉。 – Bonnie 2013-05-13 12:58:26

+0

沒有用戶會通過點擊選擇一個貼紙,只有該貼紙會旋轉,縮放或移動 – Gaurav 2013-05-13 13:00:56

回答

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

注意:只要你想

+0

當任何貼紙是選擇是否需要每次創建一個新的UIImageView? 然後將手勢添加到該視圖 – Gaurav 2013-05-13 13:29:30

+0

如果沒有看到您的代碼伴侶,我什麼也不能說。你是什​​麼意思由var? * confused * – Ushan87 2013-05-13 13:31:48

+0

o o無論如何,這將有助於其實我需要在像其他照片應用程序的圖像上添加貼紙..我有多個貼紙 現在你建議爲每個貼紙添加一個imageview。 – Gaurav 2013-05-13 13:40:02

0

我期待當你particuler圖像單擊要執行對particuler肖像權有所行動,然後再嘗試這樣可能it'l幫助你

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: 
} 
+0

是的,但我不知道如何進一步進行,如如何在選定的視圖上執行旋轉,縮放等 – Gaurav 2013-05-13 13:15:26

+0

然後發生什麼? – Balu 2013-05-13 13:18:59

+0

我希望在選擇任何貼紙時提供指導我需要爲每個貼紙創建一個新的UIImageView,然後如何將gestureRecognizer添加到這個新視圖 – Gaurav 2013-05-13 13:32:32