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!
-
Is the search function on StackOverflow and/or Google broken? stackoverflow.com/questions/7035640/…Nick Bull– Nick Bull2012年01月24日 13:40:16 +00:00Commented Jan 24, 2012 at 13:40
-
Mr Bull, I took a look at similar questions before posting, I think the root of my problem is different.Eric– Eric2012年01月24日 13:53:00 +00:00Commented Jan 24, 2012 at 13:53
-
Would be helpful if you edited your question and told people what you have tried...Nick Bull– Nick Bull2012年01月24日 14:03:24 +00:00Commented Jan 24, 2012 at 14:03
1 Answer 1
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;
}
];
}
];
}