简体   繁体   English

如何找到与UIScrollView框架的中心x相等的contentView的x坐标

[英]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.

相关问题 如何根据用户对图像的触摸获得X和Y坐标,在任何设备上都相同 - How can I get an X and Y coordinate, based on a user's touch on an image, that will be the same on any device 检查UIScrollVIew的contentOffset是否等于某个x值 - Check if a UIScrollVIew's contentOffset is equal to a certain x value 如何在UIScrollView缩放上更新UIScrollView的ContentView子视图分辨率? - How to update UIScrollView's ContentView's subviews resolution on UIScrollView zoom? 如何通过坐标/位置(x,y)查找UIView - How to find an UIView by a coordinate/location (x,y) 我在 UIScrollView 中有一个 UIImageView。 如何以编程方式以图像的 x,y 为中心? - I have an UIImageView in an UIScrollView. How do I center at x,y of the image programmatically? 如何在坐标中居中 GMSMapMarker 视图 - How can I center the GMSMapMarker view in a coordinate 如何找出UIScrollView滚动指示器的大小? - How can I find out the size of a UIScrollView's Scroll Indicator? 如果初始帧配置错误,如何在使用 AutoLayout 时获取 UIView 的 (x, y)? - How can I get UIView's (x, y) when using AutoLayout if initial frame was misconfigured? 在UIScrollView容器视图的坐标系中确定UIScrollView的子视图框架 - Determining a UIScrollView's subview frame in the coordinate system of UIScrollView's container view 根据UIScrollView的中心点在UIScrollView中找到CGPoint - Find CGPoint of view inside UIScrollView depending of UIScrollView's center point
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM