无限缩放 CATiledlayer iOS
有没有办法在每次处于更深的缩放级别时重置缩放级别,以便您可以进行无限缩放?
我正在尝试创建一个 CATiledLayer,其中每个图块都有不同的颜色,当您放大图块时,您只会获得新的颜色,依此类推。
Is there a way to reset your zoomlevel each time you're on a deeper zoomlevel so you can have an endless zoom?
I'm trying to create a CATiledLayer where each tile has a different color and when you zoom into a tile you just get new colors, and so on.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定如何使用 CATiledLayer 执行此操作,但 Matt Neuburg 所著的《Programming IOS 4》一书包含“Zooming with Detail”一节,其中描述了如何使用 UIScrollView 执行类似的操作。
UIScrollView 支持双指缩放放大其内容,但它只是通过缩放变换来放大其内容的未缩放渲染,而不是以更高的 ZoomScale 重新渲染其内容。因此,为了提供实际显示更多细节的缩放,您需要添加一些逻辑。
基本上,这本书建议您实现scrollViewDidEndZooming:withView:atScale:以便它(1)将UIScrollView的zoomScale重置为其默认值1.0,并且(2)删除内容视图并提供一个新视图,其中包含所需真实缩放比例的内容。您需要引入自己的 ivar 来手动跟踪这个真实的比例。结果是,当您进一步放大并且真实比例不断单调增加时,UIScrollView 包含一系列不同的视图,并在其边界内不断循环其自己的 ZoomScale,从 1.0 到最大值,然后重置为 1.0,然后从 1.0 到最大值等等。本书给出了一个骨架示例(第 506 页,第一版,第二次印刷)。
您将如何使用它进行无限缩放?如果您不需要真正无限的缩放,则可以在真实比例的非常大的范围内执行上述操作。
如果您想要真正无限的缩放,则无法使用真实比例的有限边界变量来跟踪缩放级别。相反,您可以修改scrollViewDidEndZooming:withView:atScale:,以便它(1)将UIScrollView的zoomScale重置为其默认值1.0,(1)删除内容视图并提供一个新视图,其中新视图的新zoomScale为1.0 在视觉上与旧缩放级别的删除视图相同。这样,当用户通过捏合手势不断放大时,UIScrollView 会重复从 1.0 循环到最大值,在每个循环中、在用户手势之间无形地替换底层视图。
I'm not sure about how to do this with CATiledLayer, but the book Programming IOS 4, by Matt Neuburg, includes a section "Zooming with Detail" which describes how to do something similar using UIScrollView.
UIScrollView offers support for pinch-out zooming into its contents, but it just magnifies the unzoomed rendering of its contents with a scale transform rather than re-rendering its contents at the higher zoomScale. Therefore, in order to provide zooming that actually shows increased detail, you need to add some logic.
Basically, the book suggests you implement scrollViewDidEndZooming:withView:atScale: so that it (1) resets UIScrollView's zoomScale to its default value of 1.0, and (2) removes the contents view and provides a new view with contents at the desired true zoom scale. You need to introduce your own ivar to track this true scale manually. The result is that, as you zoom further in and the true scale keeps increasing monotonically, the UIScrollView houses a succession of different views and keeps cycling its own zoomScale within its bounds, from 1.0 to max, then reset to 1.0, then 1.0 to max, etc.. The book gives a skeletal example (p 506 in the 1st edition, second printing of the book).
How would you use this for endless zooming? If you don't need truly endless zooming, you can just do the above with a very large range for the true scale.
If you want truly endless zooming, you can't track your zoom level with a finitely-bounded variable for the true scale. Instead, you'd modify scrollViewDidEndZooming:withView:atScale: so that it (1) resets UIScrollView's zoomScale to its default value of 1.0, (1) removes the contents view and provides a new view, where the new view at the new zoomScale of 1.0 is visually identical to the removed view at the old zoomLevel. In this way, as the user kept zooming in with pinch-out gestures, UIScrollView would repeatedly cycle from 1.0 to max, invisibly replacing the underlying view at each cycle, in between the user's gestures.