UIScrollView + pagingEnabled, scroll half a page?

Discussion in 'iOS Programming' started by iphoneSDKrules, Jan 14, 2009.

  1. iphoneSDKrules
    Expand Collapse
    macrumors newbie

    Joined:
    Aug 21, 2008
    #1
    Hello,

    can anyone tell me if it is possible, to scroll half a page in a UIScrollView with pagingEnabled = true.

    As far as I know, the amount of scrolling when pagingEnabled depends on the frame size of the ScrollView, so it scrolls exactly one page.What I'd like to do is scrolling exactly half a page: my ScrollView contains two images on each 'page' and after scrolling I don't want to display the next two images, but the second image of the previous page + the first image of the next page and so on...

    I'd be so glad if anyone could tell me how to do so.

    thanks for your help, kate :)
     
  2. walty
    Expand Collapse
    macrumors member

    Joined:
    Jul 15, 2008
    #2
    hm.. I have seen such scenario (as a bug) in uitableview, but not sure if it worked the same as uiscrollview.

    have u tried to make the frame size of the scrollview TWICE the size of screen? in that way, the second half may never be scrolled to.
     
  3. zkiraly
    Expand Collapse
    macrumors newbie

    Joined:
    Jan 15, 2009
    #3
    I am also interested in the same. Right now I have a workaround in place, but being able to page arbitrary distances would be nice.

    Zsolt
     
  4. dejo
    Expand Collapse
    Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    That doesn't sound like paging to me, which, as I understand it, is scrolling non-arbitrary distances.

    My suggestion to everyone would be to set pagingEnabled = NO and scrollingEnabled = NO and then capture the swipe events and then call scrollRectToVisible to scroll to where you want it. I'm not certain this will work but it's worth a shot.
     
  5. zkiraly
    Expand Collapse
    macrumors newbie

    Joined:
    Jan 15, 2009
    #5
    Thanks for the suggestion. Actually, that's what I do now. But there is no 'bounce' at the end, like in the weather app.

    I think this is still 'paging.' Imagine the weather app, but zoomed out, so you see a portion of the adjoining pages as well. That's kinda what I'd like to accomplish in my own app.
     
  6. iphoneSDKrules
    Expand Collapse
    thread starter macrumors newbie

    Joined:
    Aug 21, 2008
    #6
    Thank you! That solves my problem!
    I set paginEnabled + scrollingEnabled to NO and capture swipes using the touchesBegan and touchesEnded methods. Depending on a positive or negative yDistance between the two touch locations, I call the scrollRectToVisible in order to scroll half a page forward or backward, which works really well! :cool:
     
  7. coconutdj
    Expand Collapse
    macrumors newbie

    Joined:
    Mar 12, 2009
    #7
    hi iphoneSdkRules,
    i have the same problem , i want to scroll a half page, can you send me that piece of code to see hot to do this ?
    " I set paginEnabled + scrollingEnabled to NO and capture swipes using the touchesBegan and touchesEnded methods. Depending on a positive or negative yDistance between the two touch locations, I call the scrollRectToVisible in order to scroll half a page forward or backward, which works really well! "

    Thanks
    coconut_dj@yahoo.com
     
  8. iphoneSDKrules
    Expand Collapse
    thread starter macrumors newbie

    Joined:
    Aug 21, 2008
    #8
    hi, this is what i did in touchesBegan & touchesEnded methods:

    PHP:
    #define SCROLLOFFSET 60

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        
    NSLog(@"TOUCHES BEGAN!");
        
        
    UITouchtouch = [touches anyObject];
        
    touchDown = [touch locationInView:self.view];
    }

    - (
    void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
    {
        
    NSLog(@"TOUCHES ENDED!");
        
        
    UITouchtouch = [touches anyObject];
        
    touchUp = [touch locationInView:[[self.view subviewsobjectAtIndex:0]];
        
        
    //calculate dragging distance
        
    double dy touchUp.touchDown.y;
        
    double dx touchUp.touchDown.x;
        
        
    NSLog(@"touchDown x: %d, y: %d"touchDown.xtouchDown.y);
        
    NSLog(@"touchUp x: %d, y:%d"touchUp.xtouchUp.y);
        
    NSLog(@"distance between touches: %d"dy);

        if(
    abs(dy) > SCROLLOFFSET)
        {
            if(
    dy 0)
                [
    self scrollForward];
            else
                [
    self scrollBackward];
        }
    }
    touchUp and touchDown are both CGPoints, the scrollForward and scrollBackward are used to call the scrollRectToVisible method with a calculated offset.

    hope that helps
     
  9. Goblin2099
    Expand Collapse
    macrumors member

    Joined:
    Jul 18, 2002
    Location:
    New York City
    #9
    Check out this post for another way to accomplish half screen paging
     

Share This Page