如何知道iPhone中当前可见视图的标签
我有一个滚动视图,我正在添加一些视图 当用户滚动时如何获取当前可见视图的标签。 然后我可以向该视图添加一些内容...
就像在表视图中获取索引路径一样..
如何做到这一点..?
谢谢
i have an scroll view and i am adding few views to that
when the user scrolls how to get the current visible view's tag.
then i can add some thing to that view...
its just like getting the indexpathrow in table view..
how to do that..?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您基本上想要检查
UIScrollView
内的子视图的框架是否与滚动视图的框架相交(如果您只想确定部分可见性),或者该框架是否包含在另一个框架中(如果您想以确定完全可见性)。但是,为了检查子视图的框架是否相交和/或包含在滚动视图的框架中,您需要将其从滚动视图内的本地坐标转换为滚动视图外的全局坐标。
这可能非常令人困惑,所以这里有一些代码。这将循环遍历滚动视图的所有子视图,并打印出它是完全可见还是部分可见:
您可以将其放入 UIScrollViewDelegate 方法中,以便在用户滚动内容时执行这些检查。
You basically want to check if the frame of the subviews inside the
UIScrollView
intersect the scrollview's frame (if you only want to determine partial visibility), or if the frame is contained in the other frame (if you want to determine full visibility).However, in order to check if the subview's frame intersects and/or is contained in the scrollview's frame you need to translate it from the local coords inside the scrollview to the global coordinates outside the scrollview.
That is probably pretty confusing, so here is some code. This will loop through all the subviews of a scrollview and print out whether it is fully visibile or partially visible:
You could put this in a
UIScrollViewDelegate
method to do these checks while the user is scrolling the content around.