問題描述
我有帶有多個 UIVIew 子視圖的 UIScrollView.當每個 UIView 出現在 UIScrollView 的可見部分時,我想更新它們顯示的數據.
I have UIScrollView with multiple UIVIew subviews. I would like to update the data that is displayed by each UIView when they appear in the visible portion of the UIScrollView.
觸發的回調是什么?我嘗試了 viewWillAppear,但它似乎沒有被調用.
What is the callback that gets triggered? I tried viewWillAppear, but it does not seem to get called.
謝謝.:)
推薦答案
你必須自己做計算.在滾動視圖委托中實現 scrollViewDidScroll:
并手動計算哪些視圖可見(例如,通過檢查 CGRectIntersectsRect(scrollView.bounds, subview.frame)
是否返回 true.
You have to do the calculation yourself. Implement scrollViewDidScroll:
in your scroll view delegate and calculate manually which views are visible (e.g. by checking if CGRectIntersectsRect(scrollView.bounds, subview.frame)
returns true.
這篇關于viewWillAppear 用于子視圖的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!