[英]How can I find the x coordinate of the contentView that is equal to the center x of a UIScrollView's frame
I have a UIScrollView
that scrolls horizontally. 我有一个
UIScrollView
可以水平滚动。 I have about 10 views lined up horizontally in that scrollview. 我有大约10个视图在该滚动视图中水平排列。 I want to find the view that contains the center point of the scrollview's frame (not contentView.frame) as it scrolls.
我想找到一个包含滚动视图框架的中心点(而不是contentView.frame)的视图。 I am thinking to use the
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
UIScrollView
delegate method, but I am not sure how to find this. 我正在考虑使用
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
UIScrollView
委托方法,但是我不确定如何找到它。
Thanks! 谢谢!
You can get the start-point of a frame of a view ( myChildView
) in the reference of another view ( scrollView
) using the following code: 您可以使用以下代码在另一个视图(
scrollView
)的引用中获取视图框架( myChildView
)的scrollView
:
CGPoint origin = [myChildView convertPoint:CGPointMake(myChildView.bounds.origin.x, myChildView.bounds.origin.y) toView:[self scrollView]];
Use the scrollViewDidScroll:
delegate method to pick your views and perform the calculations there. 使用
scrollViewDidScroll:
委托方法来选择您的视图并在那里执行计算。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.