我正在使用两个子视图。每个都将是独一无二的,并有自己的“行动”。
子视图 1 = 用户可以在视图周围拖动、旋转和缩放
子视图 2 = 当用户在屏幕上移动手指时,会在手指触摸的每个点添加图像。
我通过使用 UIPanGestureRecognizer 完成了这两项工作。我的问题是,我怎样才能将这两个动作分开?我希望能够添加一个子视图,执行所需的操作,然后当我添加另一个子视图时,防止之前的操作发生。
这是我尝试过的,这是在我的 panGesture 方法中完成的:
for (UIView * subview in imageView.subviews)
{
if ([subview isKindOfClass:[UIImageView class]])
{
if (subview == _aImageView)
{
CGPoint translation = [panRecognizer translationInView:self.view];
CGPoint imageViewPosition = _aImageView.center;
imageViewPosition.x += translation.x;
imageViewPosition.y += translation.y;
_aImageView.center = imageViewPosition;
[panRecognizer setTranslation:CGPointZero inView:self.view];
}
else if (subview == _bImageView)
{
currentTouch = [panRecognizer locationInView:self.view];
CGFloat distance = [self distanceFromPoint:currentTouch ToPoint:prev_touchPoint];
accumulatedDistance += distance;
CGFloat fixedDistance = 60;
if ([self distanceFromPoint:currentTouch ToPoint:prev_touchPoint] > fixedDistance)
{
[self addbImage];
prev_touchPoint = currentTouch;
}
}
}
}