sagarkothari
sagarkothari

Reputation: 24810

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 600px.

Upvotes: 0

Views: 3719

Answers (4)

faisal
faisal

Reputation: 475

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];

}

Upvotes: 4

No Surprises
No Surprises

Reputation: 4901

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

Upvotes: 3

Ben Gottlieb
Ben Gottlieb

Reputation: 85522

Use scrollview.contentOffset.

Upvotes: 3

NSResponder
NSResponder

Reputation: 16861

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?

Upvotes: 1

Related Questions