3

I have been searching for how to make a scroll menu with a UIScrollview wraping (looping). I checked this question and the example works and maybe it's a good approach.

But instead of showing just one page (image) I need to display 3 pages and being able to scroll one page at time.

So how can I set the UIScrollView page size 1/3 smaller than the frame (I think this way it will work)??

Is it achievable?? If not, please direct me to another direction

Thanks

Community
  • 1
  • 1
Frade
  • 2,938
  • 4
  • 28
  • 39
  • 1
    its done ;) How can I close the question?? – Frade Dec 14 '11 at 17:16
  • Thank You Sarah.. and sorry for the mistakes.. ;) – Frade Jan 11 '12 at 18:55
  • So how did you solve this? You were trying to make it so paging one page to the right, for example, left 1/3 of the previous screen showing on the left, correct? If you found out how to make each page narrower, I'd love to know how, thanks. – Ryan Apr 17 '12 at 18:46
  • Hi Ryan! Honestly, at this moment, I don't remember how did I solved the problem.. One thing I'm sure, I didn't make a page size 1/3 smaller than the frame. Maybe I build a workaround.. – Frade Sep 05 '13 at 18:39
  • I'm back on this issue :/ Does anyone has found some solution? – Frade Jul 15 '15 at 09:43
  • how can I revive this question? – Frade Jul 15 '15 at 09:44
  • @Ryan found a solution – Frade Jul 16 '15 at 09:10

3 Answers3

7

I believe what you are talking about is having a portion of the previous page and a portion of the next page visible. The way to do this is to set the scroll view's frame to be what you want (less than the screen, for example) and then turn off clipping of subviews for your scroll view. This will achieve the effect you are after.

brant
  • 369
  • 3
  • 8
  • 3
    this works (as it was my initial thought for something I'm working on), but, as I encountered, it also renders the area outside the frame unresponsive to touch/swipe. any way around that? – d2burke Apr 02 '14 at 21:48
1

After some time, I end up needing to solve this issue again.

I found a Solution that worked for me.

Check this answer:

  1. Change your scrollView size to the page size you want
  2. Set your scroll.clipsToBounds = NO
  3. Create a UIView subclass (e.g HackClipView) and override the hitTest:withEvent: method

    -(UIView *) hitTest:(CGPoint) point withEvent:(UIEvent *)event
    {     
        UIView* child = [super hitTest:point withEvent:event]; 
        if (child == self && self.subviews.count > 0)  
        {
            return self.subviews[0];
        }
        return child;
    }
    
  4. Set the HackClipView.clipsToBounds = YES

  5. Put your scrollView in this HackClipView (with the total scrolling size you want)

See this answer for more details

Update: As stated in lucius answer you can now implement the UIScollViewDelegate protocol and use the - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset method. As the targetContentOffset is a pointer. Using this method will not guarantee you the same result with scroll view pages as the user can scroll through many pages at once. But setting the descelerationRate to fast will almost give you the same result

Community
  • 1
  • 1
Frade
  • 2,938
  • 4
  • 28
  • 39
1
  1. [theScrollView setFrame:<a frame>]; will set the frame of the scroll view
  2. [theScrollView setContentSize:<a Size>]; to set the content size of your scroll view

The size in 1. should be 1/3 of the size set in 2.

Niko
  • 2,543
  • 1
  • 24
  • 29
  • Yes, you are right. But page size will be the same size as frame. The content size will be 3*frame size and it will have 3 pages. The purpose is to have a page 1/3 off the frame size. thanks anyway – Frade Dec 14 '11 at 14:22