我已经为在屏幕上摇动 UIImageView 的动画编写了代码,但是尽管语法似乎是正确的,但在构建时我得到了一个晦涩的“
internal compiler error: Bus error: 10
”。知道为什么吗?
-(IBAction)shakeCircle{
int d = 3;
[UIView animateWithDuration:0.05
animations:^{myCircle.center = CGPointMake(myCircle.center.x+d, myCircle.center.y-d);}
completion:^(BOOL finished){
[UIView animateWithDuration:0.05
animations:^{myCircle.center = CGPointMake(myCircle.center.x-d, myCircle.center.y+d);}
completion:^(BOOL finished)
{
//but if I comment from here..
[UIView animateWithDuration:0.05
animations:^{myCircle.center = CGPointMake(myCircle.center.x+d, myCircle.center.y-d);}
completion:^(BOOL finished){
[UIView animateWithDuration:0.05
animations:^{myCircle.center = CGPointMake(myCircle.center.x-d, myCircle.center.y+d);}
];
}
];
//... to here the code will build.
}
];
}
];
}
请注意,如果我注释掉动画代码的最后五行,一切都可以正常编译......发生了什么是?
我尝试过切换到不同的编译器,但没有成功。我确保只有一个
myCircle
并且它唯一被引用的时候就是它被声明的时候,并且是在那个方法中!
这里有一个通过递归调用函数来解决问题的小解决方法。 分配给
int d
摇动的量,然后
int d = 3;
-(IBAction)shakeMyCircle{
[UIView animateWithDuration:0.05
animations:^{myCircle.center = CGPointMake(myCircle.center.x+3, myCircle.center.y-3);}
completion:^(BOOL finished){
[UIView animateWithDuration:0.05
animations:^{myCircle.center = CGPointMake(myCircle.center.x-3, myCircle.center.y+3);}
completion:^(BOOL finished)
{
d--;
if(d>0) [self shakemyCircle];
if(d == 0) d = 3;
}
];
}
];
}