直接获取Button点击事件的点击坐标
作者:
Leon1024 | 来源:发表于
2019-05-28 20:30 被阅读0次原来 UIButton 的 addTarget 的 @selector 可以 传递两个参数, 一个是sender自身,一个是响应的 UIEvent :
[self.button addTarget:self action:@selector(buttonAction:event:) forControlEvents:UIControlEventTouchDown];
从 UIEvent 中可以获取 UITouch 进而获得点击的坐标
- (void)buttonAction:(UIButton *)sender event:(UIEvent *)event {
UITouch *touch = [[event touchesForView:sender] anyObject];
CGPoint point = [touch locationInView:self.view];
NSLog(@">>event:%f", point.x);
}
本文标题:直接获取Button点击事件的点击坐标
本文链接:https://www.haomeiwen.com/subject/ymujtctx.html
网友评论