动画 UIImageView 应该识别其上的点击(在 UIImageView 所在的每个位置)
我正在制作一个 iPhone 应用程序,其中涉及从屏幕底部生成并向上移动到屏幕顶部的气球(UIImageViews)。
目的是设置 UIImageViews,以便在气球上点击手势会导致气球从屏幕上移除。
我已经设置了 GestureRecognizer 并且正在识别点击。
我遇到的问题是,我正在使用的动画方法不提供有关气球在特定时间点绘制位置的信息,并将其视为已经到达提到的最终点。
这会导致仅在屏幕顶部(这是气球的最终目的地)识别点击的问题。
我在这里粘贴了我的动画代码:
UIViewAnimationOptions options = UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionAllowUserInteraction;
[UIView animateWithDuration:2.0 delay:0.0 options:options animations:^{
balloonImageView.center = p;
} completion:^(BOOL finished) {
if (finished) {
balloonImageView.hidden= TRUE;
balloonImageView.image=nil;
}
我通过给 UIImageView 提供一个唯一的标签并检查是否gesture.view.tag = anyBalloonObject.tag来跟踪图像的位置,如果是的话我销毁气球。
我的基本问题是,还有其他我可以使用的动画工具吗?我知道我可以将气球的终点设置为略高于屏幕上的位置,直到它到达顶部,但这似乎非常消耗内存。 您有什么建议吗?我浏览了核心动画参考,没有找到任何适合我需要的方法。
此外,UIViewAnimation 的多线程方面会影响点击系统的准确性吗?
谢谢你,
维克
I'm making an iPhone App which involves balloons (UIImageViews) being spawned from the bottom of the screen and moving up to the top of the screen.
The aim is to have the UIImageViews set up so that a tap gesture on a balloon causes the balloons to be removed from the screen.
I have set up the GestureRecognizer and taps are being recognized.
The problem I am having is that the animation method I am using does not provide information about where the balloon is being drawn at a specific point in time, and treats it as already having reached the final point mentioned.
This causes the problem of the taps being recognized only at the top of the screen(which is the balloon's final destination).
I have pasted my code for animation here:
UIViewAnimationOptions options = UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionAllowUserInteraction;
[UIView animateWithDuration:2.0 delay:0.0 options:options animations:^{
balloonImageView.center = p;
} completion:^(BOOL finished) {
if (finished) {
balloonImageView.hidden= TRUE;
balloonImageView.image=nil;
}
I keep track of where an image is by giving a unique tag to a UIImageView and checking if gesture.view.tag = anyBalloonObject.tag and if it does I destroy the balloon.
My basic question is, is there another animation tool I can use? I understand that I can set a balloon's finish point to slightly higher than where it is on screen until it reaches the top but that seems like it is very taxing on memory.
Do you have any recommendations? I looked through the Core Animation reference, and didn't find any methods that suited my needs.
In addition will the Multi-threading aspects of UIViewAnimation affect the accuracy of the tap system?
Thank You,
Vik
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不应该像这样为游戏对象(在移动时与之交互的对象)设置动画。
您应该使用 NSTimer 来移动气球。
以下是您需要在 .h 中声明的内容:
您必须创建一个生成方法,将气球添加到屏幕和数组中。
完成此操作后,实现触摸方法就很简单了,您只需循环气球并检查:
希望这看起来不太吓人,祝您好运。
You shouldnt animate game-objects (objects you interact with while they are moving) like that.
You should rather use a NSTimer to move the ballons.
Here is what you need to declare in .h:
You will have to create a spawn method which adds balloons to the screen AND to the array.
When you have done that, it's simple to implement the touch methods, You can just loop trough the balloons and check:
Hope that isnt too scary-looking, good luck.