質問

I've been trying to only have my UIScrollView scroll in one direction and still get all UITouch events. I'm not fully sure this is possible, at all.

I've tried to override the UIResponder's "touches" events, but as soon as the UIScrollView starts scrolling, the touches methods stop getting called.

I then tried setting the UIScrollView's scrollEnabled property to false until I want the UIScrollView to begin receiving drag events, but I can't seem to find a way to have the UIScrollView to begin receiving touch events mid-drag. Is this possible?

My next attempt was adding "padding" to the scroll view and creating my own "touch events" by playing around with the contentOffset property, but that started calling scrollViewDidScroll: an excessive amount of times and processing like crazy - also some issues with the validity of the responses.

I've played around with hitTest:withEvent:, pointInside:withEvent:, touchesShouldBegin:withEvent:inContentView: and touchesShouldCancelInContentView: without any success.

I've tried a few other things, since, but none have worked. Also, from what I've found, setting delaysContentTouches to false destroys the scroll response.

I would love some real overridden touches methods. Methods that if I don't call super, the UIScrollView doesn't receive the touches.

I need a way to get UITouches (Drags, begins, releases and cancels, not just taps), without affecting the scroll of the UIScrollView, since the UIResponder "touches" events drop off as soon as scrolling starts. Is this possible?

役に立ちましたか?

解決

If you just want to detect common touches, try attaching gesture recognizers like UITapGestureRecognizer to your view, they should work even with a UIScrollView.

You can also try placing a transparent UIView on top of the scrollview that detects some touches and passes the rest to the scrollview.

他のヒント

When you start to scroll save off a copy of the offset. Then check against it when you finish scrolling. This code allows scrolling to the left but prevents it from scrolling right

CGPoint oldOffset;
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    oldOffset = scrollView.contentOffset;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView.contentOffset.x < oldOffset.x) {
        [scrollView setContentOffset:oldOffset];
    }
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top