Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Control UIScrollView outside bounds?

I'm wondering how i can allow the user to scroll outside the bounds of a UIScrollView?

like image 392
Andrew Avatar asked Sep 12 '26 12:09

Andrew


1 Answers

Try subclassing the UIScrollView and overriding hitTest:withEvent: so that the UIScrollView picks up touches outside its bounds. Something like this:

@interface MagicScrollView : UIScrollView
@end

@implementation MagicScrollView

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    // Intercept touches 100pt outside this view's bounds on all sides
    if (CGRectContainsPoint(CGRectInset(self.bounds, -100, -100), point)) {
        return self;
    }
    return nil;
}

@end

You may also need to override pointInside:withEvent: on the UIScrollView's superview, depending on your layout.

See the following question for more info: interaction beyond bounds of uiview

like image 179
johnboiles Avatar answered Sep 15 '26 03:09

johnboiles



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!