問題描述
所以,UITableView 基本上支持無限"滾動.可能有一個限制,但那個傻瓜可以滾動很長時間.我想用 UIScrollView 來模仿這種行為,但有兩個基本障礙:
So, UITableView supports essentially "infinite" scrolling. There' may be a limit but that sucker can scroll for a looonnnggg time. I would like to mimic this behavior with a UIScrollView but there are two fundamental impediments:
1) scrollView.contentSize 在創建時是固定的.2) 縮放可以將任何延遲加載方案徹底摧毀,因為它會導致無限數據爆炸.
1) scrollView.contentSize is fixed at creation time. 2) zooming can blow any lazy-loading scheme all to hell since it can cause infinte data explosion.
有沒有其他人思考過這個想法?是的,我知道,我們本質上是在討論重新創建谷歌地圖.任何見解將不勝感激.
Have others out there pondered this idea? Yah, I know, we are essentially talking about re-creating Google Maps here. Any insights would be much appreciated.
干杯,道格
推薦答案
雖然不可能擁有真正無限的 UIScrollView,但您可以使用一些簡單的技巧來模擬這種行為.
While it's impossible to have a truly infinite UIScrollView, there are some simple tricks you can use to emulate that behavior.
- 處理固定的
contentSize
:讓滾動視圖處理一些固定大小的視圖,并在啟動或實例化時設置內容偏移量,以便您看到已處理視圖的中間.然后只需觀察內容偏移量(使用 KVO 或其他方法),如果您靠近任何邊緣,則使用一組新內容(適當偏移)更新視圖的內容并重置滾動視圖的contentOffset
屬性回到中間. - 處理縮放:做類似的事情,只是這次注意滾動視圖上的縮放系數.每當它到達某個點時,對您呈現的任何數據進行一些操作,使其顯示為已縮放,然后將縮放因子重置為 1.0.例如,如果您正在滾動圖像并且它被縮放以顯示兩倍大,則以編程方式應用某種變換以使圖像大兩倍,然后將滾動視圖的縮放因子重置為 1.0.圖像仍會放大顯示,但滾動視圖將能夠根據需要繼續進一步放大.(Google 地圖更進一步,它在用戶縮放時延遲加載更詳細的視圖 - 您可以選擇也可以不選擇實現這一點.)
- Handling the fixed
contentSize
: have some fixed-size view handled by your scroll view, and at launch or instantiation, set the content offset so that you're seeing the middle of the handled view. Then just watch the content offset (using KVO or some other method), and if you near any edge, update the content of the view with a new set of content (offset appropriately) and reset the scroll view'scontentOffset
property to be back in the middle. - Handling zooming: do something similar, only this time watch the zoom factor on the scroll view. Whenever it gets to a certain point, do some manipulation to whatever data you're presenting so that it appears zoomed, then reset the zoom factor to 1.0. For example, if you're scrolling an image and it gets zoomed to appear twice as large, programmatically apply some kind of transform to make the image twice as large, then reset the scroll view's zoom factor to 1.0. The image will still appear zoomed in, but the scroll view will be able to continue zooming in further as necessary. (Google Maps takes this one step further where it lazy-loads more detailed views as the user zooms - you may or may not choose to implement this.)
這篇關于UI滾動視圖.關于實現“無限"的任何想法滾動/縮放?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!