gpt4 book ai didi

ios - 如何等待动画——完成 block

转载 作者:行者123 更新时间:2023-12-01 16:53:39 25 4
gpt4 key购买 nike

我正在开发一个应用程序,其中两个 View 在屏幕上的某处相遇。当他们相遇时,碰撞检测器会触发这种方法。它应该识别适当的基础,然后将两个 View 都发送给它。它确实做到了,但它会立即发生,而不是在 4 秒内发生。我错过了什么? RADIUS 在此代码上方定义。它与箭头不是 UIView 有什么关系吗? spriteView 类是 UIView 的子类。

-(void)sendToBase:(spriteView *)arrow
{
int teamNumber = arrow.teamNumber;
// Find the location of the base.
for (UIView *scaledView in self.view.subviews) {
if (scaledView.tag == 100) {
for (UIView *base in scaledView.subviews) {
if (base.tag >= 1000) {
if (teamNumber + 1000 == base.tag) {
// We found the right base.
CGPoint newCenter;
newCenter.x = base.center.x + arc4random() % (int) floor(RADIUS) - RADIUS/2.0;
newCenter.y = base.center.y + arc4random() % (int) floor(RADIUS) - RADIUS/2.0;
[UIView animateWithDuration:4.0 delay:0.0 options:UIViewAnimationCurveLinear animations:^{
[arrow setCenter:newCenter];
} completion:^(BOOL finished) {
// After walking back to base, remove and create new objects
[arrow removeFromSuperview];
[self addArrow:scaledView toTeam:teamNumber];
}];
}
}
}
}
}
}

如果类类型不匹配是问题所在,我因此修改了代码,结果相同。
-(void)sendToBase:(spriteView *)arrow
{
UIView *uiSpriteView = (UIView *)arrow;
int teamNumber = arrow.teamNumber;
// Find the location of the base.
for (UIView *scaledView in self.view.subviews) {
if (scaledView.tag == 100) {
for (UIView *base in scaledView.subviews) {
if (base.tag >= 1000) {
if (teamNumber + 1000 == base.tag) {
// We found the right base.
CGPoint newCenter;
newCenter.x = base.center.x + arc4random() % (int) floor(RADIUS) - RADIUS/2.0;
newCenter.y = base.center.y + arc4random() % (int) floor(RADIUS) - RADIUS/2.0;
[UIView animateWithDuration:4.0 delay:0.0 options:UIViewAnimationCurveLinear animations:^{
[uiSpriteView setCenter:newCenter];
} completion:^(BOOL finished) {
// After walking back to base, remove and create new objects
[arrow removeFromSuperview];
[self addArrow:scaledView toTeam:teamNumber];
}];
}
}
}
}
}
}

最佳答案

根据文档,您必须使用 beginAnimations:context:commitAnimations center 的动画方法属性(property)。

关于ios - 如何等待动画——完成 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13692241/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com