2012-02-22 37 views
2

我有2個視圖。這個想法是從第二個視圖中選擇圖像並將其放置在第一個視圖上。 問題是我試圖添加平移手勢,它沒有響應或調用方法。請幫忙。在我的第一個觀點感謝UIImageView對UIPanGestureRecognizer手勢沒有響應

代碼

- (void)newStampImage: (UIImage *)inImage 
{ 
    stampImageView = [[UIImageView alloc]initWithImage:inImage]; 
    UIPanGestureRecognizer *stampPanGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(moveStamp:)]; 
    [stampPanGesture setMinimumNumberOfTouches:1]; 
    [stampPanGesture setMaximumNumberOfTouches:1]; 
    [stampImageView addGestureRecognizer:stampPanGesture]; 
    stampImageView.center = self.view.center; 
    [self.view addSubview:stampImageView]; 
} 
+0

你設置了委託嗎?[stampPanGesture setDelegate:self]; – 0xDE4E15B 2012-02-22 08:03:46

+0

@URLArenzo看到在這行代碼,並檢查目標** **:'[[UIPanGestureRecognizer的alloc] initWithTarget:自動作:@selector(moveStamp :)];' – samfisher 2012-02-22 09:58:19

+0

@samfisher抱歉,是衝浪在移動設備。 – 0xDE4E15B 2012-02-22 14:07:59

回答

12

請加

stampImageView.userInteractionEnabled = YES; 
+0

太棒了!它現在正在工作。我注意到圖像阻擋了我的按鈕。我如何將按鈕放在前面?謝謝。 – RockBaby 2012-02-22 08:12:29

+1

經典... UIImageView是唯一的UIView默認userInteractionEnabled = NO ... @RockBaby - 你應該調用[self.view bringSubviewToFront:self.myButton]; – 2012-02-22 08:16:06

+0

你可以通過'[button bringSubviewToFront:stampImageView];' – samfisher 2012-02-22 08:17:03

0

請確保你已經做了設置識別手勢,我的意思是設置gesturerecognization 屬性設置爲是,那麼它可能工作。

謝謝