iphone – 当UIButton被触发时,如何获得touchesBegan坐标?

iphone – 当UIButton被触发时,如何获得touchesBegan坐标?,第1张

概述我设置了一个touchhesBegan方法,用于在用户触摸屏幕时拾取坐标。它工作很好,除非我触摸到UIButton。我如何做到这一点,使按钮触发touchesBegan方法呢? 在按钮中添加事件处理程序,如下所示, [myButton addTarget:self action:@selector(dragBegan:withEvent:) forControlEvents: UIControlE 我设置了一个touchhesBegan方法,用于在用户触摸屏幕时拾取坐标。它工作很好,除非我触摸到UIbutton。我如何做到这一点,使按钮触发touchesBegan方法呢?解决方法 在按钮中添加事件处理程序,如下所示,

[mybutton addTarget:self action:@selector(dragBegan:withEvent:) forControlEvents: UIControlEventtouchDown];[mybutton addTarget:self action:@selector(dragMoving:withEvent:) forControlEvents: UIControlEventtouchDragInsIDe];[mybutton addTarget:self action:@selector(dragEnded:withEvent:) forControlEvents: UIControlEventtouchUpInsIDe | UIControlEventtouchUpOutsIDe];

处理以下事件,您可以从以下事件ev获取触摸点,

- (voID)dragBegan:(UIControl *)c withEvent:ev {    NSLog(@"dragBegan......");    UItouch *touch = [[ev alltouches] anyObject];    CGPoint touchPoint = [touch locationInVIEw:self.vIEw];    NSLog(@"touch x : %f y : %f",touchPoint.x,touchPoint.y);}- (voID)dragMoving:(UIControl *)c withEvent:ev {    NSLog(@"dragMoving......");}- (voID)dragEnded:(UIControl *)c withEvent:ev {    NSLog(@"dragEnded......");}

这不是我自己的答案。我从http://sree.cc/iphone/handling-touche-events-for-uibuttons-in-iphone得到这个代码,做了一些小的改动。

总结

以上是内存溢出为你收集整理的iphone – 当UIButton被触发时,如何获得touchesBegan坐标?全部内容,希望文章能够帮你解决iphone – 当UIButton被触发时,如何获得touchesBegan坐标?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1087061.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存