2012-06-14 40 views
1

我正在處理照片拼貼應用程序。我想對圖像視圖執行操作,以便任何人都可以幫助我解決問題。當我從照片庫中選擇圖像並在圖像視圖中顯示時,雙擊圖像視圖時,我想推動或呈現一個新的視圖來裁剪此圖像.....所以任何人告訴我我做什麼來解決我的問題..如何對點擊的imageview執行一些操作?

+0

作爲答案提示,如存在沒有緊迫的原因使用'UIImageView'你一定會覺得很使用自定義'UIButton' –

回答

1

您應該使用UIButton而不是UIImageView。您可以將其樣式設置爲自定義,然後將其設爲圖像。 UIButton提供了所有內置雙擊的方法。

+0

在許多情況下,這將更好的解決方案更好。它指出我在正確的方向!謝謝! – arnoapp

0

做一個按鈕,並清除它的顏色,在按鈕後面放置圖像視圖,以便您的imageview看起來像是可見的n按鈕沒有。現在將事件附加到按鈕。享受:P。

3

使用類型的自定義的一個UIButton,並把圖像裏面...... tadaaaa和你做.. :)

+0

我也檢查這一個,但當我第二次點擊按鈕時,它再次執行相同的操作,所以如何解決這個問題 –

+0

@ kuldeepsingh一旦點擊按鈕就禁用按鈕... button.userInteractionEnabled = NO; –

+0

k謝謝回覆 –

0

如果您正在使用的UIImageView,請確保您使用setUserInteractionEnabled:YES。然後你需要檢查觸摸開始,結束,(取消)。

0

設置爲使用UIImageView時,必須繼承UIImageView並覆蓋要截取的觸摸方法。例如:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    // Call super to make sure you don't lose any functionality 
    [super touchesBegan:touches withEvent:event]; 

    // Perform the actions you want to perform with the tap. 
} 

使用UIButtons爲您的UIImageViews替代的是你,只需要拖動每個按鈕的出口在您的視圖控制器的連接和處理動作一個偉大的想法。您可以像在當前使用UIImageViews一樣在按鈕上設置背景圖像。您的按鈕類型設置爲自定義,你會好到g

+0

爲什麼複雜的東西......? –

2

添加手勢爲ImageView的

UITapGestureRecognizer *sg=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(HandleEvent)]; 
    sg.numberOfTapsRequired=2; 
    [BottomBar addGestureRecognizer:sg]; 
    [sg release]; 

,並在這裏做你的任務:

-(void)HandleEvent 
{ 

// your task 
} 

感謝

+0

gd有用的帖子 –

0

如果您正在使用UIImageView類,首先設置setUserInteractionEnabled:YES。然後將UITapGestureRecognizer事件設置爲圖像視圖。

0

試試下面這個

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
CGPoint locationPoint = [[touches anyObject] locationInView:self.view]; 
    CGPoint viewPoint = [imageView convertPoint:locationPoint fromView:self.view]; 
    if ([imageView pointInside:viewPoint withEvent:event]) { 
     //do something 
    } 
} 
相關問題