这就是我在UIScrollView
viewDidLoad
的方法
UIScrollView* scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
scrollView.backgroundColor = [UIColor redColor];
scrollView.scrollEnabled = YES;
scrollView.pagingEnabled = YES;
scrollView.showsVerticalScrollIndicator = YES;
scrollView.showsHorizontalScrollIndicator = YES;
scrollView.contentSize = CGSizeMake(self.view.bounds.size.width , self.view.bounds.size.height * 2);
[self.view addSubview:scrollView];
scrollView.delegate = self;
第一次加载scrollView时,它的坐标为:{(0,0), (widthOfiPhone, 0), (0, heightOfiPhone), (widthOfiPhone, heightOfiPhone)}
每当滚动完成,我想在scrollview中获得视口的坐标。这该怎么做?感谢
图片来源:https://oleb.net/blog/2014/04/understanding-uiscrollview/
答案 0 :(得分:0)
您可以实施UIScrollView delegate
方法来检测滚动结束的时间:scrollViewDidEndDecelerating
,在此方法中,您可以获得scrollview
及content
的坐标。顺便说一句content's
cooridinate与尊重scrollview !!!相同!
您可以从滚动视图中获取visible rect
,
CGRect visibleRect = [subViewOfScrollView convertRect:subViewOfScrollView.bounds toView:self.view];
答案 1 :(得分:0)
首先,观察scrollview代理,然后实现其代理方法
(void) scrollViewDidEndDecelerating: (UIScrollView *) scrollView {
NSLog (@ "% f,% f,% f,% f", scrollView.frame.origin.x,
scrollView.frame.origin.y,
scrollView.frame.size.width,
scrollView.frame.size.height);
}
这应该是可能的