S
S
SVM122015-08-03 10:24:46
iOS
SVM12, 2015-08-03 10:24:46

How do I prevent an event (such as touched) from being passed to the parent Superview?

In general, there is a parent View (Room Scheme View).
There is a child leaving translucent TableView.
Now after tap(select) in TableView, this tap is passed on to the parent View(Room Scheme View)
How to make sure that this tap is not passed to the parent View(Room Scheme View)?
1082894659dc4367987b5c07d3c9f911.png

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Volodymyr Lavryk, 2015-08-04
@Vo0ne

Maybe this will help you?

A
Alexander Tikhonov, 2015-08-04
@tikhonov666

The information you provided is not enough. Therefore, a tap cannot simply be transmitted to the parent. Which is exactly what I just checked. Check on which views the tap happens, for example, in this controller method.

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        for touch in touches {
            print(touch.view)
        }
    }

S
SVM12, 2015-08-13
@SVM12

Temporarily solved the problem like this:
RoomSchemeView.h:

/// необрабатываемая зона, в этой области тапы не обрабатываются
@property (nonatomic, assign) CGRect unprocessedRect;

RoomSchemeView.m
- (void)tap:(UIGestureRecognizer *)gr
{
    CGPoint point = [gr locationInView:self];
    // проверяем находится ли точка в необрабатываем зоне
    if (!CGRectEqualToRect(self.unprocessedRect, CGRectZero) && CGRectContainsPoint(self.unprocessedRect, point)) {
        NSLog(@"tap with point %@ in unprocessed rect %@", NSStringFromCGPoint(point), NSStringFromCGRect(self.unprocessedRect));
        return;
    }
    ...
}

RoomSchemeViewController.m:
- (void)showTableView
{
    if (!self.tableIsVisible) {
        self.tableView.frame = CGRectMake(-self.tableView.frame.size.width, self.tableView.frame.origin.y, self.tableView.frame.size.width, self.tableView.frame.size.height);
        [UIView animateWithDuration:.3 animations:^{
            self.tableView.frame = CGRectMake(0, self.tableView.frame.origin.y, self.tableView.frame.size.width, self.tableView.frame.size.height);
        } completion:^(BOOL finished) {
            self.tableIsVisible = YES;
            self.roomSchemeView.unprocessedRect = self.tableView.frame;
        }];
    }
}

- (void)hideTableView
{
    if (self.tableIsVisible) {
        self.tableView.frame = CGRectMake(0, self.tableView.frame.origin.y, self.tableView.frame.size.width, self.tableView.frame.size.height);
        [UIView animateWithDuration:.3 animations:^{
            self.tableView.frame = CGRectMake(-self.tableView.frame.size.width, self.tableView.frame.origin.y, self.tableView.frame.size.width, self.tableView.frame.size.height);
        } completion:^(BOOL finished) {
            self.tableIsVisible = NO;
            self.roomSchemeView.unprocessedRect = CGRectZero;
        }];
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question