Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

john903

macrumors member
Original poster
Apr 11, 2008
66
0
Is there a way to get the position of the scroll bars in a UIScrollView?
 

Niiro13

macrumors 68000
Feb 12, 2008
1,719
0
Illinois
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.
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
There are no scroll bars in a scrollview. I think what you want are contentOffset and setContentOffset:
 

john903

macrumors member
Original poster
Apr 11, 2008
66
0
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];
}
 

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
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
 

john903

macrumors member
Original poster
Apr 11, 2008
66
0
Ah, Thanks! I was printing the values out using "%d". Works now!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.