Get touches from UIScrollView
Posted
by
Peter Lapisu
on Stack Overflow
See other posts from Stack Overflow
or by Peter Lapisu
Published on 2012-07-07T09:12:18Z
Indexed on
2012/07/07
9:15 UTC
Read the original article
Hit count: 234
cocoa
|uiscrollview
Basically i want to subclass UIScrollView and hande the touches, however, the touch methods dont get called
(i searched the web for a solution and i found out people pointing to override the hit test, what i did, but with no result :( )
.h
@interface XScroller : UIScrollView
@end
.m
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView *result = nil;
for (UIView *child in self.subviews) {
if ([child pointInside:point withEvent:event]) {
if ((result = [child hitTest:point withEvent:event]) != nil) {
break;
}
}
}
return result;
}
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"BEGAN");
[super touchesBegan:touches withEvent:event];
}
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"MOVED");
[super touchesMoved:touches withEvent:event];
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"ENDED");
[super touchesEnded:touches withEvent:event];
}
- (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"CANCELED");
[super touchesCancelled:touches withEvent:event];
}
none of the - (void) touches* methods get called, the scrolling works ok
© Stack Overflow or respective owner