ios - 使用 UIView Animation 在 Xcode 中制作动画时,按钮不执行被点击的操作

标签 ios objective-c xcode animation uiview

我有一个正在制作的游戏,我正在尝试使用 UIView 动画移动一个名为 tapMe 的按钮,但我需要它在制作动画时可以录制。

[UIView animateWithDuration:0.5 animations:^{
    _tapMe.center = CGPointMake(xRandom, yRandom);
}];

其中 xRandom 和 yRandom 是随机生成的整数,而 _tapMe 连接到按钮,我敢肯定,因为它确实会移动。

最佳答案

当您使用 animateWithDuration 时,按钮的框架会立即移动到它的最终位置(在那里它将是可触摸的),但是表示层是动画的,因此您在动画期间看到按钮的位置不是可触摸区域所在的位置.您要么需要点击测试表示层,要么通过使用计时器以小增量移动按钮来为按钮设置动画。有关更多详细信息,请参见此处的答案,UIButton can't be touched while animated with UIView animateWithDuration

关于ios - 使用 UIView Animation 在 Xcode 中制作动画时,按钮不执行被点击的操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27434863/

相关文章:

objective-c - 在 MAC 10.3.9 Cocoa 中解析和写入 XML?

objective-c - Storyboard的问题

iphone - 在 objective-c 中生成唯一的ID

objective-c - _objc_retain”,引用自 :__ARCLite__load error in Xcode 4. 4

ios - 如何将 HKBloodType 枚举转换为字符串

ios - 自定义 UITableViewCell 中的按钮 Segue

ios - NSLocalizedString - 线程 1 : EXEC_BAD_ACCESS with String. localizedStringWithFormat

iPhone 5 隐藏在 View 中的栏的布局

ios - Cocoapods 错误 : unable to update after adding new Facebook iOS SDK

iPhone:如何设置 UIViewController 框架?