UIScrollView - 为新的contentSize设置合适的contentOffset产生不良的空白空间 [英] UIScrollView - setting proper contentOffset for new contentSize yields undesirable empty space

查看:257
本文介绍了UIScrollView - 为新的contentSize设置合适的contentOffset产生不良的空白空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在用UIScrollView玩弄了一会儿。我想要的是根据各种因素插入子视图到scrollView。因为我有scrollview只在垂直方向滚动,我会插入子视图之前或之后的当前可见视图。



所以,让我说我当前的可见视图的帧是0,0,320,480),scrollView的contentSize是(320,480),当前contentOffset是(0,0)



当我想在currentView上插入子视图, currentView在焦点,我插入新的子视图在位置(0,-480,320,480),并将scrollView的contentSize更改为(320,960),同时保持contentOffset相同为(0,0)。



发生的令人惊讶的事情是,UIScrollView在currentView之后添加额外空间,而不是在currentView上面。虽然上面新插入的视图永远不能被带入焦点coz UIScrollView假设contentSize从一个错误的contentOffset可能!



我googled,发现有一些其他面临类似的问题,但没有产生结果:
设置UIScrollView的内容大小的起点



请让我知道,如果我做错了什么?

谢谢!



编辑:一些 主题 表示更改contentSize将影响contentOffset属性,以确保这不是造成问题,我更新contentOffset属性只有在我改变contentSize之后。

解决方案

始终总是(0,0)。如果要插入高于当前偏移量的东西,您需要将当前视图向下移动 480 points ,添加新视图(0 ,0)并将contentOffset设置为(0,480)(和contentSize到(320,960)


I have been juggling for a while with UIScrollView now. What I am trying is to insert subviews into the scrollView based on various factors. Since I have scrollview to scroll only in vertical direction, I would insert the subview before or after the current visible view.

So, lets say my current visible view's frames are (0,0,320,480), the contentSize of scrollView is (320,480) and current contentOffset is (0,0)

When I want to insert subview above the currentView and yet keep the currentView in focus, I insert the new subview at the position (0,-480,320,480) and change the contentSize of scrollView to (320, 960) while keeping the contentOffset same as (0,0).

The surprising thing which happens is, UIScrollView adds "extra" space after the currentView instead of inserting it above the currentView. While the newly inserted view above can never be brought into focus coz UIScrollView is assuming the contentSize from a wrong contentOffset perhaps!

I googled and found that there are some others facing similar problems, but did not yield results yet: Set starting point of content size for UIScrollView

Please let me know if I am doing anything wrong? Or is this some kind of limitation etc?

Thanks!

Edit: Some threads suggests that changing the contentSize will affect contentOffset property, so to make sure that this is not causing problem, I am updating the contentOffset property only after I change the contentSize. Even then I am facing same problems.

解决方案

The origin is always (0,0). If you want to insert something above the current offset you'll want to move the current views down by 480 points, add the new view at (0,0) and set the contentOffset to (0,480) (and the contentSize to (320,960).

这篇关于UIScrollView - 为新的contentSize设置合适的contentOffset产生不良的空白空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆