UIScrollView。任何关于实现“无限”滚动/缩放? [英] UIScrollView. Any thoughts on implementing "infinite" scroll/zoom?

查看:185
本文介绍了UIScrollView。任何关于实现“无限”滚动/缩放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,UITableView本质上支持无限滚动。可能有一个限制,但吸盘可以滚动一个looonnnggg时间。我想用一个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.

有其他人在那里考虑这个想法吗? Yah,我知道,我们实际上是在这里重新创建Google地图。非常感谢任何见解。

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.

干杯,
Doug

Cheers, Doug

推荐答案

虽然不可能有一个真正无限的UIScrollView,但有一些简单的技巧可以用来模拟这种行为。

While it's impossible to have a truly infinite UIScrollView, there are some simple tricks you can use to emulate that behavior.


  1. 固定的 contentSize :有一些由滚动视图处理的固定大小的视图,并且在启动或实例化时,设置内容偏移,以便看到处理的视图。然后只是观看内容偏移(使用KVO或其他方法),如果你靠近任何边缘,用一组新的内容(适当偏移)更新视图的内容,并重置滚动视图的 contentOffset 属性返回中间。

  2. 处理缩放:做类似的操作,只有这一次在滚动视图上观看缩放系数。每当它到达某一点时,对您呈现的任何数据进行一些操作,以使其显示为缩放,然后将缩放系数重置为1.0。例如,如果您滚动图像并将图像缩放到显示两倍的大小,以编程方式应用某种变换,使图像的两倍大,然后将滚动视图的缩放系数重置为1.0。图像仍会放大,但滚动视图将能够根据需要继续进一步放大。 (Google地图会延长这一步,因为延迟会随着用户缩放而载入更详细的视图 - 您可能也可能不会选择实施此操作。)

  1. 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's contentOffset property to be back in the middle.
  2. 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.)

这篇关于UIScrollView。任何关于实现“无限”滚动/缩放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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