I have written code for an animation that shakes a UIImageView on the screen, but although the syntax seems to be correct, I am getting an obscure "internal compiler error: Bus error: 10
" when building. Any idea why?
-(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.
}
];
}
];
}
Note that if I comment out the last five lines of animation code, everything compiles fine.... What is going on?
I have tried switching to different compilers, that didn't work. I made sure that there's just one myCircle
and that the only time it ever gets referred to is when it gets declared, and in that method!
Here's a little workaround that solves the problem through recursive calls to the function. Assign to int d
the amount by which to shake, then
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;
}
];
}
];
}