I have two view controllers. View controller A has a UIScrollView
and presents view controller B. The presentation is interactive and controlled by the sc
Try subclassing the UIScrollView
and overriding hitTest:withEvent:
so that the UIScrollView
picks up touches outside its bounds. Then you get all the nice UIScrollView
animations for free. 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. Customize this for the touch area you want to intercept
if (CGRectContainsPoint(CGRectInset(self.bounds, -100, -100), point)) {
return self;
}
return nil;
}
@end
Or in Swift (Thanks Edwin Vermeer!)
class MagicScrollView: UIScrollView {
override func hitTest(point: CGPoint, withEvent event: UIEvent?) -> UIView? {
if CGRectContainsPoint(CGRectInset(self.bounds, -100, -100), point) {
return self
}
return nil
}
}
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