2011-06-25 38 views
0

我想從觸摸獲取座標,但我無法弄清楚如何。
我在視圖控制器,我嘗試使用方法-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event,但我認爲它不適用於視圖控制器。
對嗎?獲取觸摸的座標並在該位置放置一個按鈕?

我只是想把一個按鈕放在我感動的位置。

在此先感謝!

回答

1

它屬於一個視圖,而不是視圖控制器,並會是這個樣子:

-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)evt { 
    UITouch *touch=[touches anyObject]; 
    CGPoint pt=[touch locationInView:self]; 
    // ...make your button at 'pt'... 
}