UIScrollView - position of scroll bars

Discussion in 'iOS Programming' started by john903, Sep 22, 2008.

  1. macrumors member

    Joined:
    Apr 11, 2008
    #1
    Is there a way to get the position of the scroll bars in a UIScrollView?
     
  2. macrumors 68000

    Joined:
    Feb 12, 2008
    Location:
    Illinois
    #2
    Not that I know of.

    But the scrollers to screen should be the same relation as the center of the scrollview is to its content.
     
  3. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #3
    There are no scroll bars in a scrollview. I think what you want are contentOffset and setContentOffset:
     
  4. thread starter macrumors member

    Joined:
    Apr 11, 2008
    #4
    Yes. That's what I want! I'm trying to find this out in the scrollViewDidScroll method in my UIScrollViewDelegate. I did this but point returned is always {0,0}. Do you know what I'm doing wrong? Thanks!

    Code:
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView
    {
    	CGPoint point = [scrollView contentOffset];
    }
    
     
  5. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #5
    Don't know what you're doing wrong. How do you know the value of the point? Probably the x value will always be 0. y should change. This works for me:

    Code:
    - (void)scrollViewDidScroll:(UIScrollView *)inscrollView
    {
    	CGPoint	p = inscrollView.contentOffset;
    	
    	NSLog(@"x = %f, y = %f", p.x, p.y);
    }
    
    I get results like:

    Code:
    2008-09-22 21:04:16.122 ScrollViewTest[29247:20b] x = 0.000000, y = 13.000000
    2008-09-22 21:04:16.138 ScrollViewTest[29247:20b] x = 0.000000, y = 29.000000
    2008-09-22 21:04:16.155 ScrollViewTest[29247:20b] x = 0.000000, y = 47.000000
    2008-09-22 21:04:16.172 ScrollViewTest[29247:20b] x = 0.000000, y = 63.000000
    
     
  6. thread starter macrumors member

    Joined:
    Apr 11, 2008
    #6
    Ah, Thanks! I was printing the values out using "%d". Works now!
     

Share This Page