是否有可能成功的动画移动的UIButton? [英] Is it possible to successful animate a moving UIButton?

查看:112
本文介绍了是否有可能成功的动画移动的UIButton?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想动画一个按钮,在屏幕上移动。在任何时候,用户可以按下按钮。但按钮并不触摸响应。我试过动画块,但按钮即可立即移动到其终点坐标,而框显示动画(按钮被称为泡沫):

I'm trying to animate a button which moves around the screen. At any point, the user can push the button. But the button doesn't respond to touches. I've tried an animation block but the button simply moves immediately to its end coordinates, while the frame shows the animation (the button is called bubble):

[UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:5.0];
    CGAffineTransform newTransform = CGAffineTransformMakeScale(3, 3);
    bubble.transform = CGAffineTransformTranslate(newTransform, 0, -460);
    [UIView commitAnimations];

于是我试着Core Animation的一些示例code的帮助(路径并不重要,它只是一个例子):

So then I tried Core Animation with the help of some sample code (the path isn't important, it's just an example):

CGMutablePathRef thePath = CGPathCreateMutable();
    CGPathMoveToPoint(thePath,NULL,15.0f,15.f);
    CGPathAddCurveToPoint(thePath,NULL,
                          15.f,250.0f,
                          295.0f,250.0f,
                          295.0f,15.0f);
    CAKeyframeAnimation *theAnimation=[CAKeyframeAnimation animationWithKeyPath:@"position"];
    theAnimation.path=thePath;
    CAAnimationGroup *theGroup = [CAAnimationGroup animation];
    theGroup.animations=[NSArray arrayWithObject:theAnimation];
    theGroup.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
    theGroup.duration=15.0;
    CFRelease(thePath);
    [bubble.layer addAnimation:theGroup forKey:@"animatePosition"];

但按键还是不来触摸响应。顺便说一句,我有一次这么有几个NSTimers同时激活不会是最优的几个屏幕上的这些泡沫的按钮。

But the buttons still don't respond to touches. Btw, I have several of these 'bubble' buttons on screen at once so having several NSTimers concurrently active wouldn't be optimal.

任何人都可以提出另一种方法?我或许应该动画的UIImageViews,使他们repsond到触摸?或将我有同样的问题?这一直困扰我几天,所以任何帮助不大AP preciated。

Can anyone suggest another approach? Should I perhaps animate UIImageViews and make them repsond to touches? Or will I have the same problem? This has been puzzling me for a couple of days so any help much appreciated.

谢谢:)

迈克尔

推荐答案

这听起来有点太复杂的UIKit和CoreAnimation。好像你正在开发类似游戏。为什么不使用的假设〜60 fps的,做你的图形中Quartz2D一个全球性的动画计时器?然后为每个触摸,你可以快速检查石英刷新之间的任何命中。

This sounds a bit too complicated for UIKit and CoreAnimation. It seems like you're developing something like a game. Why not use a global animation timer for let's say ~60 fps and do your drawing in Quartz2D? Then for each touch you could quickly check any hits between Quartz refreshes.

这篇关于是否有可能成功的动画移动的UIButton?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆