最近做项目时,遇到需要获取 按钮点击事件时 触摸点具体在button中的坐标,琢磨了半天终于搞出来了,下面直接上方法代码。
- (IBAction)buttonPressed:(id)sender forEvent:(UIEvent*)event
{
UIView *button = (UIView *)sender;
UITouch *touch = [[event touchesForView:button] anyObject];
CGPoint location = [touch locationInView:button];
NSLog(@"Location in button: %f, %f", location.x, location.y);
}