UIScroll view current position in iPhone
Suppose I have a scroll view in a view & a scroll view's size is 320 width, 2000 height.
When user scrolls & decelerating stops, I want to know where a scroll view has stopped?
i.e. at 300px or 400px or at开发者_C百科 600px.
you can track that afeter scrolling, what is the coordinate of the origin, using the following two methods. This are two delegate methods conforms to your UIScrollView class.
-
(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)newScrollView
{
NSLog(@"scrollViewDidEndScrollingAnimation");
CGPoint p = scrollView.contentOffset;
int curr= floor(p.x/320);
NSLog(@"x=%f,y=%f,curr=%d",p.x,p.y,curr);
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)newScrollView
{
[self scrollViewDidEndScrollingAnimation:newScrollView];
}
Use scrollview.contentOffset.
When the scroll view is done scrolling, it fires off some events to its UIScrollViewDelegate
:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
You can implement those methods in the delegate to find out the new contentOffset
of your UIScrollView
:
@property(nonatomic) CGPoint contentOffset
You can find out where any view is situated relative to its superview by looking at its frame rect. What are you trying to do?
精彩评论