从窗口中删除时,UIScrollview contentOffset发生更改 [英] UIScrollview contentOffset changes when removed from window

查看:232
本文介绍了从窗口中删除时,UIScrollview contentOffset发生更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于UIScrollView的怪异错误。此视图可以正常工作,直到我将其从窗口中删除(间接地,它是已删除视图的子视图)为止。

I have a weird bug concerning an UIScrollView. This view works fine, until the moment I remove it from the window (indirectly, it's a subview to a removed view).

然后我执行一些无关的动画;并且当我将视图放置在原处时,scrollView的contentOffset发生了变化。

I then perform some unrelated animation ; and when I put the views where they were, the scrollView's contentOffset has changed.

我在setContentOffset:函数中放置了一个断点,并得到了以下堆栈:

I put a breakpoint in setContentOffset: function, and got the following stack :

#0  -[TestScrollView setContentOffset:] (self=0x915fbd0, _cmd=0x7fb34cd, contentOffset={x = 80, y = -0}) at /Users/../TestScrollView.m:19
#1  0x008670ea in -[UIScrollView(Static) _adjustContentOffsetIfNecessary] ()
#2  0x0085db55 in -[UIScrollView(UIScrollViewInternal) _stopScrollingNotify:dealloc:pin:] ()
#3  0x0084e6ff in -[UIScrollView _didMoveFromWindow:toWindow:] ()
#4  0x008444bb in -[UIView(Internal) _didMoveFromWindow:toWindow:] ()
#5  0x008444bb in -[UIView(Internal) _didMoveFromWindow:toWindow:] ()
#6  0x008444bb in -[UIView(Internal) _didMoveFromWindow:toWindow:] ()
#7  0x008444bb in -[UIView(Internal) _didMoveFromWindow:toWindow:] ()
#8  0x00840c72 in -[UIView(Hierarchy) _postMovedFromSuperview:] ()
#9  0x0083f4c6 in __UIViewWasRemovedFromSuperview ()
#10 0x0083f141 in -[UIView(Hierarchy) removeFromSuperview] ()
#11 0x00166573 in __98+[App MyAnimationLaunchingMethod]_block_invoke_0 ...

当滚动视图将自己的contentOffset从调用更改为_adjustContentOffsetIfNecessary时,例如在setFrame之后,我看到了其他问题。
但是这里似乎没有任何意义,因为它的大小没有变化:它只是从屏幕上取下(稍后再放回去)。因此,没有理由更改其偏移量。

I saw other questions when a scrollview changes its own contentOffset from a call to _adjustContentOffsetIfNecessary, for instance after a setFrame. However it doesn't seem to make any sense here, as its size doesn't change : it is just taken off from the screen (to be put on back later). So there's no reason for it to change its offset.

对此是否有解释?有什么方法可以防止这种变化?

Is there some explanation to this ? Some way to prevent this change ?

我可以手动阻止(或还原)偏移量更改,但是我正在寻找一种干净的解决方案(如果有):从窗口中删除的整个视图。有时,这种特殊的scrollView通常不会出现在视图树中。因此,动画类不应该知道滚动视图。

I could block (or restore) manually the offset change, however I'm looking for a "clean" solution if available : it's a whole group of views which are removed from the window. Sometimes this particular scrollView is present in the views tree, usually not.. So the animation class should not know about the scrollview.

有什么想法吗?

预先感谢

推荐答案

有种破解方法,但是您可以进行测试 setContentOffset:,如果它已经从其超级视图中删除,则简单地返回。

Kind of a hack, but you can put a test in your setContentOffset: and simply return if it has already been removed from its superview.

这篇关于从窗口中删除时,UIScrollview contentOffset发生更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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