简体   繁体   English

UIScroll在iPhone中查看当前位置

[英]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. 假设我在一个视图中有一个滚动视图,并且一个滚动视图的大小是320宽,2000高度。

When user scrolls & decelerating stops, I want to know where a scroll view has stopped? 当用户滚动和减速停止时,我想知道滚动视图在哪里停止了?

ie at 300px or 400px or at 600px. 即300px或400px或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. 这是两个与UIScrollView类一致的委托方法。

- --

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

}

使用scrollview.contentOffset。

When the scroll view is done scrolling, it fires off some events to its UIScrollViewDelegate : 滚动视图完成滚动后,将向其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 : 您可以在委托中实现这些方法,以查找UIScrollView的新contentOffset

@property(nonatomic) CGPoint contentOffset

You can find out where any view is situated relative to its superview by looking at its frame rect. 您可以通过查看其框架rect来找到任何视图相对于其父视图的位置。 What are you trying to do? 你想做什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM