在 MKMapView 上对精灵进行动画处理
无需进入 OpenGL(Quartz 2D 即可):
假设我有一个图像,我想以某种流畅的方式在地图上移动。例如,飞机“飞过”地图的图像。我已经能够使用 MKAnnotation、NSTimer 并调整纬度/经度变化率和计时器速率来做到这一点。然而,我认为这并不理想,尽管结果看起来相当不错。你能想出更好的方法吗?
现在假设我希望该图像具有动画效果(例如:动画 gif)。我无法使用一系列
animationFrames
执行通常的UIImageView
操作,因为我在 MKAnnotationView 中可以访问的只是一个UIImage
。你们会如何解决这个问题?
我意识到#2 可以通过包含动画图像的地图顶部的 UIImageView 来处理。但是,当地图视图区域发生变化时,我必须手动处理翻译飞机或火箭或其他任何内容的运动,具体取决于现实世界中的用户运动或用户缩放(我的应用程序中不允许滚动)。
你怎么认为?
Without getting into OpenGL (Quartz 2D is OK):
Let's say I have an image which I want to move across a map in some fluid way. For instance, an image of a plane "flying" across the map. I've been able to do this using an MKAnnotation, an NSTimer and fiddling with the rate of lat/lon change and timer rate. However, I assume this isn't ideal, although the results look pretty decent. Can you think of a better way?
Now let's say that I want this image to be animated (think: animated gif). I can't do the usual
UIImageView
with a series ofanimationFrames
because all I have access to in MKAnnotationView is aUIImage
. How would you guys tackle this?
I realize that #2 could be handled with a UIImageView on top of the map containing the animationImages. However, then I would have to manually handle translating the movement of the plane or rocket or whatever as the region of the mapview changed, depending on user movements in the real-world, or user zooming (scrolling is not allowed in my app).
What do you think?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我已经找到了#2 的解决方案。我对 MKAnnotationView 进行了子类化,并编写了一些代码来添加 UIImageView(带有动画图像)作为子视图。
//动画注释.m
I think I've figured out a solution to #2. I subclassed MKAnnotationView and wrote some code to add a UIImageView (with animation images) as a subview.
//AnimatedAnnotation.m