Taps are not recognized in the table when contentOffset is set to a negative value

I have a table view and I add a sub view directly to the table view with addSubview:. I show this view in position CGRectMake(0.0f, -30.0f, tableView.frame.size.width, 30.0f)(therefore it is displayed above the scrollable area of ​​the table when the user scrolls slightly outside the scroll area). Then I do this:

- (void) scrollViewDidScroll:(UIScrollView *)scrollView {
    if(scrollView.contentInset.top + scrollView.contentOffset.y < -30.0f) {
        [scrollView setContentOffset:CGPointMake(1.0f, -30.0f)-scrollView.contentInset.top animated:NO];
    }
}

Thus, when the user scrolls up and into the negative space in the table view, when they are released they can still see what I put in y = -30 so that the table does not “snap back” to 0.

Everything works the way I want. However, when the table is contentOffsetset to a negative value of y, such as [scrollView setContentOffset:CGPointMake(1.0f, -30.0f)-scrollView.contentInset.top animated:NO], then the strokes are NOT recognized both in the cells of my table and in the view that I inserted directly into the table. I am wondering how I can set contentOffset to that value, and still have child views of my tableView, as well as cells, register strokes.

+4
source share
1 answer

It may be easier to just add 30.0fin contentInset.topso that you can continue to use the stock table view.

, hitTest:withEvent: UITableView:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    if (CGRectContainsPoint(self.theViewInQuestion.frame, point)) {
        return self.theViewInQuestion;
    }

    return [super hitTest:point withEvent:event];
}

iOS , , , theViewInQuestion, , .

" iOS - hitTest: withEvent: pointInside: withEvent: ?" , , .

0

All Articles