我对UIGestures很熟悉,但这种特殊需求让我深受其害。
问题:如何找到起点两点并结束UIPinchGesture的两个点?
我必须得到所有这四点,并且必须在服务器端进行一些计算。
有人曾尝试过吗?
答案 0 :(得分:8)
使用
- (CGPoint)locationOfTouch:(NSUInteger)touchIndex inView:(UIView *)view
像
[gesture locationOfTouch:0 inView:youView]; //first
[gesture locationOfTouch:1 inView:youView]; //second
答案 1 :(得分:1)
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touchPositionOne = [[[event allTouches] allObjects] objectAtIndex:0];
UITouch *touchPositionTwo = [[[event allTouches] allObjects] objectAtIndex:1];
CGPoint fps = [touchPositionOne locationInView:self.imageView];
CGPoint sps = [touchPositionTwo locationInView:self.imageView];
NSLog(@"%@ %@", NSStringFromCGPoint(fps), NSStringFromCGPoint(sps));
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touchPositionOne = [[[event allTouches] allObjects] objectAtIndex:0];
UITouch *touchPositionTwo = [[[event allTouches] allObjects] objectAtIndex:1];
CGPoint fps = [touchPositionOne locationInView:self.imageView];
CGPoint sps = [touchPositionTwo locationInView:self.imageView];
NSLog(@"%@ %@", NSStringFromCGPoint(fps), NSStringFromCGPoint(sps));
}
答案 2 :(得分:0)
CGPoint point1 = [gestureRecognizer locationOfTouch:0 inView:piece];
CGPoint point2 = [gestureRecognizer locationOfTouch:1 inView:piece];
CGPoint center = [gestureRecognizer locationInView:piece];
答案 3 :(得分:0)
我认为在 XCode 12 中你可以使用 location(ofTouch:, in:) 来识别点的位置:
print(sender.location(ofTouch: 0, in: view))
print(sender.location(ofTouch: 1, in: view))