Ios 我如何知道手指触摸开始和结束的位置?
我需要手指接触的位置来画一条线,以及当我放下手指时线的结束位置 我应该使用哪个图书馆?Ios 我如何知道手指触摸开始和结束的位置?,ios,iphone,xcode,Ios,Iphone,Xcode,我需要手指接触的位置来画一条线,以及当我放下手指时线的结束位置 我应该使用哪个图书馆? 如何在xcode中执行此操作?推荐的方法是将UIPangestureRecognitor附加到视图中,并解释从中获得的消息 您还可以实现UIView的自定义子类,设置userInteractionEnabled=TRUE,然后实现touchesBegind:withEvent:、touchesMoved:withEvent:、以及toucheSend:withEvent:方法 您应该能够找到许多示例应用程序,
如何在xcode中执行此操作?推荐的方法是将UIPangestureRecognitor附加到视图中,并解释从中获得的消息 您还可以实现UIView的自定义子类,设置userInteractionEnabled=TRUE,然后实现touchesBegind:withEvent:、touchesMoved:withEvent:、以及toucheSend:withEvent:方法 您应该能够找到许多示例应用程序,展示如何在线完成此操作。尝试用谷歌搜索“UIPangestureRecognitizer绘制线”。借用自 这是苹果的文件:。在
UIView
或UIViewController
的子类中,可以添加以下方法:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touched = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touched.view];
NSLog(@"x=%.2f y=%.2f", location.x, location.y);
}
这只会获得触摸的开始。您需要保存触摸并在touchesEnded中匹配它们。最好使用邓肯提出的方法