Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A <code>UIScrollView</code> with paging enabled will stop at multiples of its frame width (or height). So the first step is to figure out how wide you want your pages to be. Make that the width of the <code>UIScrollView</code>. Then, set your subview's sizes however big you need them to be, and set their centers based on multiples of the <code>UIScrollView</code>'s width.</p> <p>Then, since you want to see the other pages, of course, set <code>clipsToBounds</code> to <code>NO</code> as mhjoy stated. The trick part now is getting it to scroll when the user starts the drag outside the range of the <code>UIScrollView</code>'s frame. My solution (when I had to do this very recently) was as follows:</p> <p>Create a <code>UIView</code> subclass (i.e. <code>ClipView</code>) that will contain the <code>UIScrollView</code> and it's subviews. Essentially, it should have the frame of what you would assume the <code>UIScrollView</code> would have under normal circumstances. Place the <code>UIScrollView</code> in the center of the <code>ClipView</code>. Make sure the <code>ClipView</code>'s <code>clipsToBounds</code> is set to <code>YES</code> if its width is less than that of its parent view. Also, the <code>ClipView</code> needs a reference to the <code>UIScrollView</code>.</p> <p>The final step is to override <code>- (UIView *)hitTest:withEvent:</code> inside the <code>ClipView</code>.</p> <pre><code>- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { return [self pointInside:point withEvent:event] ? scrollView : nil; } </code></pre> <p>This basically expands the touch area of the <code>UIScrollView</code> to the frame of its parent's view, exactly what you need.</p> <p>Another option would be to subclass <code>UIScrollView</code> and override its <code>- (BOOL)pointInside:(CGPoint) point withEvent:(UIEvent *) event</code> method, however you will still need a container view to do the clipping, and it may be difficult to determine when to return <code>YES</code> based only on the <code>UIScrollView</code>'s frame.</p> <p><strong>NOTE:</strong> <em>You should also take a look at Juri Pakaste's <a href="https://stackoverflow.com/a/1373096/11109">hitTest:withEvent: modification</a> if you are having issues with subview user interaction.</em></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload