Skip to content

Instantly share code, notes, and snippets.

@indragiek
Created November 19, 2011 20:15
Show Gist options
  • Save indragiek/1379303 to your computer and use it in GitHub Desktop.
Save indragiek/1379303 to your computer and use it in GitHub Desktop.
AppKit autoscroll implemented in UIKit
@interface UIView (Autoscroll)
- (void)autoscroll:(UITouch*)touch;
@end
@implementation UIView (Autoscroll)
- (void)autoscroll:(UITouch*)touch
{
// Pass the autoscroll messages onto the superview until it reaches a view that handles the message
// If you want to pass the messages through the responder chain then this category would need to be
// implemented on UIResponder instead of UIView and you would call [self.nextResponder autoscroll:touch]
[self.superview autoscroll:touch];
}
@end
@interface UIScrollView (Autoscroll)
@end
@implementation UIScrollView (Autoscroll)
- (void)autoscroll:(UITouch*)touch
{
// UIScrollView handles the autoscroll message
CGPoint location = [touch locationInView:self];
CGRect scrollRect = CGRectMake(location.x, location.y, 10.f, 10.f);
[self scrollRectToVisible:scrollRect animated:NO];
}
@end
// Usage: just call -autoscroll: in -touchesMoved:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[self autoscroll:[touches anyObject]];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment