我试图检测 aUIPinchGestureRecognizer
方法中的触摸,因为我需要水平和垂直比例。在捏合时,应相应调整图像大小。例如,如果用户只水平移动手指,我只调整视图的宽度。
它工作正常,但是当我将手指放在屏幕上时,大多数情况下应用程序会因 SIGABRT 而崩溃并且没有消息。
我的代码是:
if (recognizer.state == UIGestureRecognizerStateBegan) {
previousHorizontalPinchDistance = ABS([recognizer locationOfTouch:1 inView:recognizer.view].x - [recognizer locationOfTouch:0 inView:recognizer.view].x);
previousVerticalPinchDistance = ABS([recognizer locationOfTouch:1 inView:recognizer.view].y - [recognizer locationOfTouch:0 inView:recognizer.view].y);
}
CGFloat horizontalPinchDistance = ABS([recognizer locationOfTouch:1 inView:recognizer.view].x - [recognizer locationOfTouch:0 inView:recognizer.view].x);
CGFloat verticalPinchDistance = ABS([recognizer locationOfTouch:1 inView:recognizer.view].y - [recognizer locationOfTouch:0 inView:recognizer.view].y);
崩溃发生在我设置horizontalPinchDistance
. 知道为什么吗?谢谢!