<tfoot id='EmsOq'></tfoot>

        <bdo id='EmsOq'></bdo><ul id='EmsOq'></ul>

      1. <small id='EmsOq'></small><noframes id='EmsOq'>

        <i id='EmsOq'><tr id='EmsOq'><dt id='EmsOq'><q id='EmsOq'><span id='EmsOq'><b id='EmsOq'><form id='EmsOq'><ins id='EmsOq'></ins><ul id='EmsOq'></ul><sub id='EmsOq'></sub></form><legend id='EmsOq'></legend><bdo id='EmsOq'><pre id='EmsOq'><center id='EmsOq'></center></pre></bdo></b><th id='EmsOq'></th></span></q></dt></tr></i><div id='EmsOq'><tfoot id='EmsOq'></tfoot><dl id='EmsOq'><fieldset id='EmsOq'></fieldset></dl></div>
      2. <legend id='EmsOq'><style id='EmsOq'><dir id='EmsOq'><q id='EmsOq'></q></dir></style></legend>

        是否有可能成功地为移动的 UIButton 设置动画?

        时间:2023-07-08

          <i id='0X6Jb'><tr id='0X6Jb'><dt id='0X6Jb'><q id='0X6Jb'><span id='0X6Jb'><b id='0X6Jb'><form id='0X6Jb'><ins id='0X6Jb'></ins><ul id='0X6Jb'></ul><sub id='0X6Jb'></sub></form><legend id='0X6Jb'></legend><bdo id='0X6Jb'><pre id='0X6Jb'><center id='0X6Jb'></center></pre></bdo></b><th id='0X6Jb'></th></span></q></dt></tr></i><div id='0X6Jb'><tfoot id='0X6Jb'></tfoot><dl id='0X6Jb'><fieldset id='0X6Jb'></fieldset></dl></div>

            <small id='0X6Jb'></small><noframes id='0X6Jb'>

            <tfoot id='0X6Jb'></tfoot>

                • <bdo id='0X6Jb'></bdo><ul id='0X6Jb'></ul>
                • <legend id='0X6Jb'><style id='0X6Jb'><dir id='0X6Jb'><q id='0X6Jb'></q></dir></style></legend>

                    <tbody id='0X6Jb'></tbody>

                  本文介绍了是否有可能成功地为移动的 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(路径并不重要,它只是一个示例):

                  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"];
                  

                  但按钮仍然不响应触摸.顺便说一句,我在屏幕上同时有几个这样的气泡"按钮,所以同时激活多个 NSTimer 并不是最佳选择.

                  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 设置动画并让它们响应触摸?或者我会遇到同样的问题吗?这让我困惑了几天,所以非常感谢任何帮助.

                  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 中进行绘图?然后,对于每次触摸,您都可以快速检查 Quartz 刷新之间的任何命中.

                  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 设置动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 iOS 8 中通过外观代理设置 UIButton 字体? 下一篇:如何以编程方式将 UIButton 调整为文本大小并保持漂亮的填充?

                  相关文章

                    <tfoot id='EoITn'></tfoot>

                    <i id='EoITn'><tr id='EoITn'><dt id='EoITn'><q id='EoITn'><span id='EoITn'><b id='EoITn'><form id='EoITn'><ins id='EoITn'></ins><ul id='EoITn'></ul><sub id='EoITn'></sub></form><legend id='EoITn'></legend><bdo id='EoITn'><pre id='EoITn'><center id='EoITn'></center></pre></bdo></b><th id='EoITn'></th></span></q></dt></tr></i><div id='EoITn'><tfoot id='EoITn'></tfoot><dl id='EoITn'><fieldset id='EoITn'></fieldset></dl></div>

                    <small id='EoITn'></small><noframes id='EoITn'>

                      <bdo id='EoITn'></bdo><ul id='EoITn'></ul>

                      <legend id='EoITn'><style id='EoITn'><dir id='EoITn'><q id='EoITn'></q></dir></style></legend>