A UIScrollView with paging enabled will stop at the edges of its width (or height). So, the first step is to find out how wide you want your pages to be. Make the width of the UIScrollView . Then set the subtask sizes, whatever you need, and set their centers based on multiples of UIScrollView .
Then, since you want to see other pages, of course, set clipsToBounds to NO , as indicated by mhjoy. Now the trick is getting it to scroll when the user starts dragging and dropping outside the UIScrollView frame. My solution (when I needed to do this recently) was as follows:
Create a subclass of UIView (i.e. ClipView ) that will contain the UIScrollView and its subclauses. Essentially, it should have the structure of what you would assume that a UIScrollView would have normal circumstances. Place the UIScrollView in the center of the ClipView . Make sure that ClipView clipsToBounds set to YES if its width is less than its parent view. In addition, ClipView requires a link to UIScrollView .
The final step is to override - (UIView *)hitTest:withEvent: inside ClipView .
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { return [self pointInside:point withEvent:event] ? scrollView : nil; }
This basically extends the touch area of ββthe UIScrollView to the frame of its parent view, exactly what you need.
Another option would be to subclass UIScrollView and override its method - (BOOL)pointInside:(CGPoint) point withEvent:(UIEvent *) event , however, to perform cropping you still need a container view, and it can be difficult to determine when to return YES based only on on a UIScrollView .
NOTE. You should also take a look at Juri Pakaste hitTest: withEvent: modify if you are having problems interacting with the subview user.
Ed Marty Aug 03 '09 at 3:48 2009-08-03 03:48
source share