簡體   English   中英

從窗口中刪除時,UIScrollview contentOffset會發生更改

[英]UIScrollview contentOffset changes when removed from window

我有一個關於UIScrollView的奇怪錯誤。 這個視圖工作正常,直到我從窗口中刪除它(間接地,它是移除視圖的子視圖)。

然后我執行一些不相關的動畫; 當我把視圖放在原來的位置時,scrollView的contentOffset已經改變了。

我在setContentOffset:function中放了一個斷點,得到了以下堆棧:

#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 ...

當一個scrollview從調用_adjustContentOffsetIfNecessary時調用自己的contentOffset時,我看到了其他問題,例如在setFrame之后。 然而,它似乎沒有任何意義,因為它的大小不會改變:它只是從屏幕上取下(以后再放回去)。 所以它沒有理由改變它的偏移量。

對此有一些解釋嗎? 有什么方法可以防止這種變化?

我可以手動阻止(或恢復)偏移量變化,但是我正在尋找一個“干凈”的解決方案(如果可用):它是從窗口中刪除的整組視圖。 有時這個特殊的scrollView存在於視圖樹中,通常不會..因此動畫類不應該知道scrollview。

任何的想法 ?

提前致謝

有點破解,但是你可以在你的setContentOffset:進行測試setContentOffset:如果已經從superview中刪除了它,則返回。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM