Iphone 将触摸传递到下一个响应者或其他子视图iOS

Iphone 将触摸传递到下一个响应者或其他子视图iOS,iphone,objective-c,uiview,uiimageview,touch,Iphone,Objective C,Uiview,Uiimageview,Touch,我相信这个问题会很容易解决,但是我对iOS开发还比较陌生。我正在尝试处理传递触摸事件给UIView上绘图顺序较低的孩子。例如— 我创建扩展UIImageView来创建我的MoveableImage类。这个类基本上就是UIImageView,它实现了ToucheSBegind、touchesEnded和touchesMoved- -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self showFrame]

我相信这个问题会很容易解决,但是我对iOS开发还比较陌生。我正在尝试处理传递触摸事件给UIView上绘图顺序较低的孩子。例如—

我创建扩展UIImageView来创建我的MoveableImage类。这个类基本上就是UIImageView,它实现了ToucheSBegind、touchesEnded和touchesMoved-

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{


[self showFrame];

//if multitouch dont move
if([[event allTouches]count] > 1)
{
    return;
}



    UITouch *touch = [[event touchesForView:self] anyObject ];

    // Animate the first touch
    CGPoint colorPoint = [touch locationInView:self];

    CGPoint touchPoint = [touch locationInView:self.superview];


    //if color is alpha of 0 , they are touching the frame and bubble to next responder
    UIColor *color = [self colorOfPoint:colorPoint];
    [color getRed:NULL green:NULL blue:NULL alpha:&touchBeganAlpha];
    NSLog(@"alpha : %f",touchBeganAlpha);

    if(touchBeganAlpha > 0)
    {
          [self animateFirstTouchAtPoint:touchPoint];
    }
    else {
        [super.nextResponder touchesBegan:touches withEvent:event];
    }



}
所以最终的结果基本上是这样的-如果他们接触到imageView的框架,而不是下面的另一个图像中的图像可能会响应。请参见此图以获取示例

到目前为止,我已经尝试了下一个响应,但这并不能解决问题。任何帮助都将不胜感激

已解决-我停止检查触摸开始和触摸移动时的alpha。Ovvering pointInside允许UIView为我处理这个问题

-(BOOL) pointInside:(CGPoint)point withEvent:(UIEvent *) event
{
  BOOL superResult = [super pointInside:point withEvent:event];
  if(!superResult)
  {
   return superResult;
  }

  if(CGPointEqualToPoint(point, self.previousTouchPoint))
  {
     return self.previousTouchHitTestResponse;
  }else{
     self.previousTouchPoint = point;
  }

  BOOL response = NO;

  //if image is nil then return yes and fall back to super
  if(self.image == nil)
   {
     response = YES;
   }

  response = [self isAlphaVisibleAtPoint:point];
  self.previousTouchHitTestResponse = response;
  return response;





}

您可以为UIImageView的子类重写
-(BOOL)pointInside:(CGPoint)pointwithevent:(UIEvent*)event
方法。(这是每个子类都可以重写的uiview方法)

UIView在hitTest:withEvent:中使用此方法来确定哪个子视图应接收触摸事件。如果pointInside:withEvent:返回YES,则遍历子视图的层次结构;否则,将忽略其视图层次的分支

检查的github上的源代码。它们只处理按钮不透明部分的点击事件