加载subView时禁用superview上的用户交互

时间:2014-10-14 08:12:13

标签: ios objective-c iphone

我正在创建自定义下拉菜单及其功能,因为我想要它,当我点击选择按钮时弹出它,但是当按钮上的子视图弹出时我想要在我的超级视图上禁用所有用户交互,这就是我被困住的地方。

当我将菜单作为subView添加到superview时,我尝试禁用它,但它会禁用所有触摸事件,包括我的子视图。

任何人都可以帮助我。

这是我的实施

- (void) showPopUpWithTitle:(NSString *)popupTitle withOption:(NSArray *)arrOptions xy:(CGPoint)point size:(CGSize)size
{    
    dropDownObject = [[DropDownMenu alloc] initWithTitle:popupTitle options:arrOptions xy:point size:size];
    dropDownObject.delegate = self;

    [dropDownObject showInView:self.view animated:YES];
    [dropDownObject SetBackGroundDropDwon_R:0.0 G:110 B:185.0 alpha:0.60];

}

这里dropDownObject返回一个自定义tableView,它位于我想在屏幕中心弹出的框架内,无论iphone模型如何

showInView in方法,将此对象添加到当前视图中,该视图在另一个类dropDownMenu.m中定义

这里是它的实现

- (void)showInView:(UIView *)aView animated:(BOOL)animated
{
    [aView addSubview:self];
    if (animated)
    {
        [self fadeIn];
    }
}

我还实现了视图动画fadeIn和fadeOut

- (void)fadeIn
{
    self.transform = CGAffineTransformMakeScale(0.5, 0.5);
    self.alpha = 0;
    [UIView animateWithDuration:.35 animations:^{
        self.alpha = 1;
        self.transform = CGAffineTransformMakeScale(1, 1);
    }];

}
- (void)fadeOut
{
    [UIView animateWithDuration:.35 animations:^{
    self.transform = CGAffineTransformMakeScale(0.5, 0.5);
    self.alpha = 0.0;
  } completion:^(BOOL finished) {
        if (finished) 
        {
            [self removeFromSuperview];
        }
    }];
}

1 个答案:

答案 0 :(得分:0)

将点击手势添加到要添加下拉视图的视图

   tapgesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(rmovetheoverlay:)];
   tapgesture_.delegate=self;
   tapgesture_.enabled=YES;
   [<viewwhereaddeddropdown> addGestureRecognizer:mTapGestureRecognizer_];

   - (void)rmovetheoverlay:(UITapGestureRecognizer *) gestureRecognizer{


    }
  - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
        DLog(@"touch view %@",[touch.view superview]);
        DLog(@"touch view %@",touch.view);
        if (([touch.view isKindOfClass:[UISearchBar class]] && touch.view==mSearchBar_)||[[touch.view superview] isKindOfClass:[UITableViewCell class]]) {
            // prevent recognizing touches on the dropdowntable
            return NO;
        }

        return YES;
    }