UIScrollView. Any thoughts on implementing quot;infinitequot; scroll/zoom?(UI滚动视图.关于实现“无限的任何想法滚动/缩放?)
问题描述
所以,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滚动视图.关于实现“无限"的任何想法滚动/缩放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UI滚动视图.关于实现“无限"的任何想法滚动
基础教程推荐
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01