Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 我如何知道手指触摸开始和结束的位置?_Ios_Iphone_Xcode - Fatal编程技术网

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中匹配它们。最好使用邓肯提出的方法