Iphone 触摸时移除覆盖视图

Iphone 触摸时移除覆盖视图,iphone,uiview,objective-c++,Iphone,Uiview,Objective C++,我将UIview定义为覆盖视图: self.disableViewOverlay = [[UIView alloc] initWithFrame:CGRectMake(0.0f,44.0f,320.0f,416.0f)]; self.disableViewOverlay.backgroundColor=[UIColor blackColor]; self.disableViewOverlay.alpha = 0; 现在我想禁用覆盖视图,如果用户点击它 [disableViewOverlay r

我将UIview定义为覆盖视图:

self.disableViewOverlay = [[UIView alloc] initWithFrame:CGRectMake(0.0f,44.0f,320.0f,416.0f)];
self.disableViewOverlay.backgroundColor=[UIColor blackColor];
self.disableViewOverlay.alpha = 0;
现在我想禁用覆盖视图,如果用户点击它

[disableViewOverlay removeFromSuperview];
如何确定用户是否点击此覆盖视图?是否有一个“点击”的方法,就像一个按钮有一个iAction

谢谢

您有两个选择:

  • 覆盖
    ui视图中的
    hitTest

  • 覆盖
    触摸开始:withEvent:
    触摸移动:withEvent:
    触摸结束:withEvent:
    ,以获得更好的控制

  • 这两种方法都需要对
    UIView
    (要检测点击的)进行子类化

    分别看一看

    如果您不想将您的
    UIView
    子类化,另一个选项是将其附加到
    uiapgesturecognizer

     gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapOnView)];
     [self.disableViewOverlay addGestureRecognizer:gestureRecognizer];
    
    然后在
    handleTapOnView
    功能中禁用覆盖。 手势识别器仅在iOS 3.2上提供

    选中此项:

    您有两个选项:

  • 覆盖
    ui视图中的
    hitTest

  • 覆盖
    触摸开始:withEvent:
    触摸移动:withEvent:
    触摸结束:withEvent:
    ,以获得更好的控制

  • 这两种方法都需要对
    UIView
    (要检测点击的)进行子类化

    分别看一看

    如果您不想将您的
    UIView
    子类化,另一个选项是将其附加到
    uiapgesturecognizer

     gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapOnView)];
     [self.disableViewOverlay addGestureRecognizer:gestureRecognizer];
    
    然后在
    handleTapOnView
    功能中禁用覆盖。 手势识别器仅在iOS 3.2上提供

    选中此项: