I've set scrollView.userInteractionEnabled to NO so that superview catches the touch event.
In appro开发者_如何学JAVApriate times, from one of my custom view class I call
scrollView.userInteractionEnabled = YES;
[scrollView touchesBegan: touches withEvent: event];
or moved/ended similarly.
I can see that my scrollView is getting the touche event messages with my debug output.
But I don't see it scrolling how could this be?contentSize is big enough and scrollEnabled is YES.
(When I set scrollView.userInteractionEnabled = YES at start up, the scrollView scrolls fine)for instance, my subclass of UIScrollView has
- (void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event
{
SYSLOG(LOG_DEBUG, "MyScrollView touchesBegan");
[self setUserInteractionEnabled: YES];
[self setScrollEnabled: YES];
[super touchesBegan: touches withEvent: event];
}
- Edit
overloading touchesBegan in a view class or view controller class makes a difference maybe?
Looks like you can't just pass touches in and have it respond to them :(
You would have to use the [UIScrollView setContentOffset:animated:] method to move the scrollview yourself.
A better way of intercepting the touches might be to put a view in front of the scrollview - grab any touches you want to listen to and then pass it to the next responder in the chain.
You would make a subclass of UIView that overrode the touch handling methods, something like :
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if (scrollViewShouldGetThisTouch)
[self.nextResponder touchesBegan:touches withEvent:event];
}
and just make this view have the same frame as your scrollview but be infront of it in the ui (transparent of course!).
OR
You could subclass UIScrollView - though this might result in odd errors if Apple ever change the implementation of a UIScrollView. I'd choose the other option!
精彩评论