【问题标题】:Get the coordinates of a touch and place a button on that position?获取触摸的坐标并在该位置放置一个按钮?
【发布时间】:2011-06-25 16:22:16
【问题描述】:
我正在尝试通过触摸获取坐标,但我不知道如何。
我在视图控制器中,我尝试使用 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 方法,但我认为它不适用于视图控制器。
我对吗?
我只想在我触摸的位置放一个按钮。
提前致谢!
【问题讨论】:
标签:
ipad
uiviewcontroller
uibutton
uigesturerecognizer
uitouch
【解决方案1】:
它属于 View 而不是 ViewController,看起来像这样:
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)evt {
UITouch *touch=[touches anyObject];
CGPoint pt=[touch locationInView:self];
// ...make your button at 'pt'...
}