【问题标题】:How to animate(move) a UIButton, keeping it touchable during the move?如何动画(移动)UIButton,在移动过程中保持可触摸?
【发布时间】:2024-01-10 15:07:01
【问题描述】:

似乎当您为 UIButton 设置动画时,真正的按钮始终位于目标位置。动画只是一部“电影”。 在此代码中,在动画中,仅当我触摸空的最终目的地(以 600x900 为中心)时,按钮才会获取事件。如果我在显示位置看到它时触摸它,这意味着在绘制按钮的某个点(在动画中间)它什么也得不到。

CGPoint point;
point.x = 600;
point.y = 900;
[UIView animateWithDuration:16 
        delay:0 
        options:(UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionAllowAnimatedContent)
        animations:^{

            [movingbutton setCenter:point];
        }
        completion:^(BOOL finished){
            NSLog(@"animation completed");
        }
];

无法弄清楚如何在正确的动画路径中使动画按钮可触摸。任何想法? 谢谢!

【问题讨论】:

  • 当然是。什么是赏金?

标签: iphone ipad ios uibutton


【解决方案1】:

只需使用 NSTimer,并在每一步手动移动(更改帧)几个像素。

你还好吗?

【讨论】:

  • 听起来很耗费资源,是吗?
  • 不,但还是谢谢你! (我没那么懒惰;)只是想知道是否是一个更甜蜜的解决方案。 UIView 动画...行为有点令人失望。
  • 尽管优雅是你找到它的地方,但如果由我决定,我会选择它。无法想象一个按钮充当按钮会很奇怪的情况。