[英]Is there a way to get the location of a users touch while pressing UIButton?
While my user is dragging his finger while holding down a UIButton, can I get the touch location for the finger at that point? 当我的用户在按住UIButton的同时拖动他的手指时,我可以在该点获得手指的触摸位置吗? If I can't do this it seems that I could probably create a UIImageView and give it button qualities.
如果我不能这样做,我似乎可以创建一个UIImageView并给它按钮质量。 After this I would implement the touches began, moved, ended methods.
在此之后我将实现触摸开始,移动,结束方法。
These methods; 这些方法; however, do not run while a UIButton has been touched.
但是,触摸UIButton时不要运行。
The reason I need this is because I wanted to find out the direction of a touch drag outside movement, and for various other reasons too, but if this is impossible I will have to create UIImageViews I think. 我需要这个的原因是因为我想找出移动之外的触摸拖动的方向,以及其他各种原因,但如果这是不可能的,我将不得不创建UIImageViews。
Also, I do not subclass UIButton, I am too much beginner to take on apples clusters. 另外,我没有UIButton的子类,我太初学者不能使用苹果群。
you should following this: 你应该遵循这个:
[myButton addTarget:self action:@selector(dragHandler:withEvent:) forControlEvents:UIControlEventTouchDragInside];
[myButton addTarget:self action:@selector(dragHandler:withEvent:) forControlEvents:UIControlEventTouchDragOutside];
-(void)dragHandler:(UIButton *)sender withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
NSLog(@"touchInfo:%@", NSStringFromCGPoint([touch locationInView:self.view]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.