简体   繁体   中英

Disable user interaction on superview when subView is loaded

I am creating custom drop down menu and its functioning as i want it to be, it pops up when i click on select Button , but when the subView pops up on button click i want to disable all user interactions on my super view,that is where I am stuck.

I tried to disable it when i am adding my menu as subView to superview but it disables all the touch events including on my subview.

So can anybody please help me.

Here is my implementation

- (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];

}

Here dropDownObject returns me a custom tableView which is inside a frame that i want to popup in centre of screen irrespective of iphone model

showInView in method that adds this object to my current view which is defined in another class dropDownMenu.m

here its implementation

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

and i have also implemented view animations fadeIn and 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];
        }
    }];
}

Add the tap gestures to the view where you are adding the dropdown view

   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;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM