preface

Principle: Use the cancelsTouchesInView attribute to control the priority of click events

Scenario: For example, filter view, listen for the click event on the mask to hide the filter view. Prioritize the cell selection event for the filter view.

I. Set the priority of tableView click events to be lower than that of cell selected events

The cancelsTouchesInView property is used for implementation

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
    [[tap rac_gestureSignal] subscribeNext:^(id x) {
        @strongify(self);
        if (self.alpha) {
            [self.viewModel.hiddenSubject sendNext:nil]; }}]; [self addGestureRecognizer:tap];
    
    UITapGestureRecognizer *cutTap = [[UITapGestureRecognizer alloc] init];
    cutTap.cancelsTouchesInView = NO;// Set tableView click event priority, lower than the cell selected event
    [[cutTap rac_gestureSignal] subscribeNext:^(id x) {
        // @strongify(self);
        [self.viewModel.hiddenSubject sendNext:nil];

    }];
    [self.tableView addGestureRecognizer:cutTap];


Copy the code

II. Control the transmission of events in other ways

  • UIview hitTest: withEvent:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
    
    if (point.y<0) {
        return [super hitTest:point withEvent:event];
    }
    
    return self;
}


Copy the code
  • Let the subview handle the event
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
    

    
        CGPoint redBtnPoint = [self convertPoint:point toView:self.contentView];
    
   
    
        if ( CGRectContainsPoint(_imgViewdel.frame, redBtnPoint) ) {
            return _imgViewdel;
        }
    
    
    
// _imgView
        return [super hitTest:point withEvent:event];
}

Copy the code
  • GestureRecognizer Indicates the proxy mode
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{

 if ([touch.view isKindOfClass:[UITextField class]])

    {

        return NO;

    }

    / / if UITableViewCellContentView (i.e., click the tableViewCell), are not intercept Touch events

    if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {

        return NO;

    }

    return YES;

}


Copy the code

II, see aslo

IOS Horizontal Popup View can be used to perform popover operations, such as lowering/placing products, printing price tags, editing product information, synchronizing online stores, etc

Video: live.csdn.net/v/173757

Not download address: download.csdn.net/download/u0…

Demo sets two test switches:

Test switch 1: Integrate the horizontal pop-up menu view into the cell

Test switch 2: integrate the horizontal popup menu View into the VC View

Demo2 download address: download.csdn.net/download/u0…

The content of Demo2 is to integrate the horizontal pop-up menu View into the VC View

Questions answered, please pay attention to the public number: iOS reverse

1. Support to expand the collapsible pop-up menu implementation idea:

1.1 Popup view added to keyWindow, mask also added to the main window (the main reason is to click on the screen margin, need to hide popup view)

1.2 During the presentation, the animation extends from the upper right corner to the lower left foot; When hidden, the animation redraws from the lower left foot to the upper right corner.

1.3 Internal View collectionView is used for layout

1.4 The frame of the view is calculated and converted according to the commodity cell where the menu button currently clicked is located.

———————————————— Copyright Notice: this article is the original article of CSDN blogger “# public account: iOS Reverse”. It follows the COPYRIGHT agreement of CC 4.0 by-SA. Please attach the link of the original source and this notice.

The original link: blog.csdn.net/z929118967/…