2012-08-02 71 views
0

作爲我的應用程序的一部分,我需要點擊任何位於人類手部圖像內部的方法。人手圖像放置在圖像視圖中。儘管添加了手勢,但我需要添加一個按鈕。是否有可能創建一個像人手一樣的自定義按鈕在下面的圖像中完全顯示?創建像人類的自定義按鈕手

enter image description here

感謝

回答

2

創建自定義UIButton圖像添加手作爲其backgroundImagesetImage。然後在裏面使用/分配這個圖像。如下所示:

handButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    [handButton addTarget:self action:@selector(handImage_touch) forControlEvents:UIControlEventTouchUpInside]; 
    [handButton setBackgroundImage:[UIImage imageNamed:@"handIMAGE.png"] forState:UIControlStateNormal]; 
    handButton.frame = CGRectMake(x, y, width, height); 
    [self.view addSubview:handButton]; 

-(void)handImage_touch{ 
    // do anything 
} 
+0

x,y,寬度,高度會給出一個矩形 – ilhnctn 2012-08-02 07:47:06

+0

我已經測試過你說的究竟是什麼。但是我需要在圍繞手的黑色邊框中觸發該功能。 – Ganapathy 2012-08-02 09:18:35

1

我覺得起初你必須製作適合你圖片的多邊形。然後,您可以使用touchesBegan:withEvent:來獲取觸點的座標,並判斷點是否在多邊形的內部。

這裏是類似於你的問題。

How to get particular touch Area?

我認爲這是一個有點困難的工作,所以也許你會更好地使用具有碰撞判斷功能的cocos2d庫。

image

http://box2d.org/forum/viewtopic.php?f=9&t=7487

而且我認爲iOS的是構建良好的處理觸摸,所以這是對你有益的努力。