如何在iPhone上创建时间轴

问题描述:

我试图在我的iPhone应用程序中创建一个无限时间轴来滚动时间。我想我将使用一个UIScrollView这样做,但我不知道该怎么做。

I am trying to create an inifite timeline in my iPhone app to scroll through time. I think I am going to use a UIScrollView to do that but I am not sure how to do that.

我应该从头创建一个可重复使用的视图队列包含天/月/年的视图,并在他们离开屏幕时重用它们? (我记住了表格中的可重复使用的单元格)。

Am I supposed to create a reusable queue of views from scratch with views containing the days/months/years and reuse them when they go out of the screen ? (I have in mind the reusable cells from the tableviews).

也许有更好的方法吗?
感谢您的帮助!

Maybe there is a better way to do that ? Thanks for your help !

据我所知,UIScrollView 3.0以来没有宽度限制。然而,你不能使用它来显示大量的数据,因为它需要太多的时间来绘制它,你的应用程序将工作缓慢。

As far as I know, UIScrollView doesn't have width limitation since 3.0. Nevertheless, you cannot use it to display large amount of data because it would take too much time to draw it and your application will work slow.

你可以使用UIView的宽度= 320.0 * 3。 Handle

You can use UIView of width = 320.0 * 3 instead. Handle

- (void) touchesMoved: (NSSet*)_touches withEvent: (UIEvent*)_event

并应用

view.transform = CGAffineTransformMakeTranslation(-shift, 0.f);

Shift可以根据从触摸设置中找到的delta X计算。仿射平移允许模拟平滑运动。当用户释放手指(touchesEnded)时,重新绘制视图(setNeedsDisplay)并移动内容,然后返回:

Shift here can be calculated depending on delta X found from touches set. Affine translation allows to emulate smooth movement. When user releases their finger (touchesEnded), redraw your view (setNeedsDisplay) with shifted content and get it back:

self.transform = CGAffineTransformIdentity;

self.transform = CGAffineTransformIdentity;

不要在touchesMoved时执行setNeedsDisplay,因为如果您正在绘制图形或计算某些内容,它可能会影响性能。

Don't do setNeedsDisplay while touchesMoved because it can affect performance if you are drawing graphs or calculating something.

对于2D地图,你必须考虑X和Y,并有320 * 3 X 480 * 3视图:)

For 2D map you would have to think about both X and Y and have 320*3 X 480*3 view :)

任务。享受。