Reputation: 3136
this code crashes with EXC_BAD_ACCESS (please forgive me the formatting, I seem to be unable to handle this web editor):
@implementation
BOOL imageZoomed=NO;
-(void)makeAnimation {
[UIView animateWithDuration:1.0f
animations:^{
self.myImageView.alpha=1.0f;
if (imageZoomed) {
self.zoomImageView.alpha=0.0f;
tempZoomImageView.alpha=1.0f;
}
}
completion:^(BOOL finished) {
if (imageZoomed) {
self.zoomImageView.alpha=1.0f;
[tempZoomImageView removeFromSuperview];
}
}
}
If I comment out the if-block in animations:, it works. imageZoomed is called before and after the animation without problems. Am I missing something with blocks and conditional clauses, or blocks and variables?
Thanks for any reply, marimba
Upvotes: 1
Views: 2113
Reputation: 21
[UIView animateWithDuration:1.0f
animations:^{
}
completion:^(BOOL finished) {
if (finished) {
}
}];
don't forget the " ]; "
Upvotes: 2
Reputation: 1348
On the surface, I don't see anything wrong with this code per se. There's nothing special WRT blocks and conditional clauses. There ARE special rules WRT variables, but looking at this code, you should probably be fine.
You probably have an object that's being over released or something along those lines. I suggest taking a close look at self, zoomImageView, and tempZoomImageView as suspects, since they're in the if block... Try enabling NSZombiesEnabled to get an exception at the point your over released object is messaged.
Upvotes: 2