Paging UIScrollView with peeking neighbor pages

后端 未结 3 513
Happy的楠姐
Happy的楠姐 2020-12-13 22:38

Look at the App Store app, on either the iPhone or the iPad, specifically the piece on the screen of app details that shows screenshots. The screenshot viewer shows you the

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-13 22:45

    You need to add a view 'behind' the scroll view which covers the entire area where your pages will be visible. This view should implement -hitTest:withEvent:. This method will get called by the OS to determine where to route a particular touch event. All you need to do is return your scroll view for any points within this backing view:

    Objective-C

    - (UIView *) hitTest: (CGPoint) pt withEvent: (UIEvent *) event {
        if (CGRectContainsPoint(self.bounds, pt)) return self.scrollView;
        return [super hitTest: pt withEvent: event];
    }
    

    Swift 4.0

    override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
        return self.bounds.contains(point) ? self.scrollView : super.hitTest(point, with: event)
    }
    

提交回复
热议问题