简体   繁体   English

滚动视图中的“绝对位置”视图

[英]“absolute position” view inside scrollview

I don't know if this is possible but maybe someone can help me: My scrollview size is 400*400px and what I want is a column/view inside on the left of the scrollview (40px wide) that always stays visible when the user scrolls horizontally, but moves together with the view when the user scrolls vertically. 我不知道这是否可行,但也许有人可以帮助我:我的滚动视图大小为400 * 400px,我想要的是滚动视图左侧(40px宽)内的一列/视图,当用户时该视图始终可见水平滚动,但当用户垂直滚动时与视图一起移动。

here's an example 这是一个例子

So the red part should always be visible when there's horizontal scrolling and the yellow part becomes visible on vertical scrolling. 因此,在进行水平滚动时,红色部分应始终可见,而在垂直滚动时,黄色部分将变为可见。 Any ideas how this can be done? 任何想法如何做到这一点?

Set yourself as the delegate of the scrollview and implement -scrollViewDidScroll: . 将自己设置为scrollview的委托,并实现-scrollViewDidScroll: In this method, check the contentOffset of the scrollView and adjust the position of your "absolutely-positioned" view accordingly. 在此方法中,检查scrollView的contentOffset并相应地调整“绝对定位”视图的位置。

Note that this method is called for every single frame of the scroll, so try not to do anything particularly expensive here. 请注意,滚动的每一帧都会调用此方法,因此在这里不要做任何特别昂贵的事情。 It may be called 60 times a second. 每秒可能被称为60次。

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

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