[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坐标?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)