質問

I have 2 descendants of UIScrollView

I have a UITableView which displays data and i have a UICollectionView added above the UITableView

view  
 | - UITableView
 | - UICollectionView

The UITableView can only scroll vertically and the UICollectionView can only scroll horizontally. I can only scroll my tableview where the collectionview isn't overlapping (which is off course expected behaviour) but i need to make it so that i can scroll my tableview even if i swipe vertically on my collectionview.

I cannot simply add the collectionview as a subview of the tableview because of other reasons (which i know, would make this work)

Is there any other possibility to let de touches from the collectionview passthrough to the tableview?

役に立ちましたか?

解決 2

As I understood, you want touches to be intercepted by UITableView as well as UICollectionView?

I think You can try resending touch events from your UICollectionView to UITableView. (manually calling touchesBegin, touchesMoved, touchesEnded, etc.)

Maybe overriding touchesBegan, touchesMoved, touchesEnded methods will work for your case.

You can try overriding UICollectionView with your subclass (with property set to your UITableView instance) and implementing touch handling methods with something like this:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesBegan:touches withEvent:event];
    if (CGRectContainsPoint(self.tableView.frame, [touch locationInView:self.tableView.superview]) {
       [self.tableView touchesBegan:touches withEvent:event];
    }
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
        [super touchesMoved:touches withEvent:event];

        [self.tableView touchesMoved:touches withEvent:event];
    }

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
        [super touchesEnded:touches withEvent:event];

        [self.tableView touchesEnded:touches withEvent:event];
    }

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
        [super touchesCancelled:touches withEvent:event];

        [self.tableView touchesCancelled:touches withEvent:event];
    }

Hope it will help, however I'm not 100% sure about it.

I've found this article also, maybe it will be useful

http://atastypixel.com/blog/a-trick-for-capturing-all-touch-input-for-the-duration-of-a-touch/

他のヒント

You can try to create a subclass of UICollectionView and add this code to your CustomCollectionView's .m file.

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    UIView *hitView = [super hitTest:point withEvent:event];
    if (hitView == self) {
        return nil;
    } else {
        return hitView;
    }
}

You can add pan gesture recognizer with direction vertical on collectionview. On the vertical pan event, you can change the content offset of your table view to scroll it.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top