(iOS) strange animation bug
(iOS) strange animation bug
- Subject: (iOS) strange animation bug
- From: WT <email@hidden>
- Date: Sat, 02 Jul 2011 16:57:37 +0100
Hello list,
so I have this little setup where, upon a user's action, a view ('notes' view, blue bg) slides down from under another view ('masking' view, black bg) while some buttons appear inside the masking view (btns 0,1,2,3). Buttons 1,2,3 start on top of btn 0 and spread out, while fading in (btn 0 stays put, and btn 2 doesn't fade). If the user then chooses to hide the notes view, it will slide back up under the masking view while buttons 1,2,3 move back on top of btn 0, fading out (resulting in btn 2 appearing where btn 0 is, but at full opacity).
My problem is that the buttons aren't moving back on top of btn 0, fading out. Rather, they simply get hidden (or their alphas are set to 0.0), *before* the sliding animation takes place. Actually, that's true only for btns 0,1,3. Btn 2 does move as expected (it's the one that shouldn't fade).
I've stared at my code for quite some time now and can't see what's wrong, so I wrote a test app that shows the problem. There is also a table view (orange bg) that should (and does) resize as the notes view slides in and out but it doesn't participate in anything interesting in the code below, so I replaced it with a regular view.
The problem happens when the app is compiled with either XCode 3.2.6 or 4.x, under iOS 4.3, on Snow Leopard 10.6.8.
The test app can be found here: (74 Kb)
http://www.restlessbrain.com/CocoaDev/AnimBug.zip
and the relevant code is:
[ apologies for the uninspired variable names and the awful-looking UI - trying to protect the innocent, so to speak :) ]
- (void) viewWillAppear: (BOOL) animated;
{
[super viewWillAppear: animated];
[self showNotesView: NO animated: NO];
}
- (IBAction) toggleNote;
{
[self showNotesView: ! notesVisible animated: YES];
}
- (void) showNotesView: (BOOL) show animated: (BOOL) animated;
{
notesVisible = show;
self.view.userInteractionEnabled = NO;
self.btn3.alpha = 0.0f;
self.btn1.alpha = 0.0f;
self.btn0.alpha = 0.0f;
self.btn3.enabled = NO;
if (! animated)
{
[self showNotesView: show];
self.view.userInteractionEnabled = YES;
}
else
{
[UIView animateWithDuration: 3.0f
animations:
^(void)
{ [self showNotesView: show]; }
completion:
^(BOOL finished)
{ self.view.userInteractionEnabled = YES; }
];
}
}
- (void) showNotesView: (BOOL) show;
{
CGFloat maskingViewBottom =
self.maskingView.frame.origin.y +
self.maskingView.frame.size.height;
CGFloat toolBarTop = self.toolbar.frame.origin.y;
CGRect notesFrame = self.notes.frame;
CGRect tableFrame = self.table.frame;
if (show)
{
notesFrame.origin.y = maskingViewBottom;
self.notes.frame = notesFrame;
tableFrame.origin.y = maskingViewBottom +
notesFrame.size.height + 10.0f;
tableFrame.size.height = toolBarTop -
tableFrame.origin.y;
self.table.frame = tableFrame;
CGPoint center = self.btn0.center;
center.x -= 37.0f;
self.btn1.center = center;
center.y -= 41.0f;
self.btn2.center = center;
center.x += 37.0f;
self.btn3.center = center;
self.btn3.alpha = 1.0f;
self.btn1.alpha = 1.0f;
self.btn0.alpha = 1.0f;
}
else
{
self.btn3.center = self.btn0.center;
self.btn1.center = self.btn0.center;
self.btn2.center = self.btn0.center;
self.btn3.alpha = 0.0f;
self.btn1.alpha = 0.0f;
self.btn0.alpha = 0.0f;
notesFrame.origin.y = maskingViewBottom -
notesFrame.size.height;
self.notes.frame = notesFrame;
tableFrame.origin.y = maskingViewBottom;
tableFrame.size.height = toolBarTop - maskingViewBottom;
self.table.frame = tableFrame;
}
}
More specifically, you can ignore the sliding in and out of the notes and table views, and focus only on the button motion/fading:
if (show)
{
CGPoint center = self.btn0.center;
center.x -= 37.0f;
self.btn1.center = center;
center.y -= 41.0f;
self.btn2.center = center;
center.x += 37.0f;
self.btn3.center = center;
self.btn3.alpha = 1.0f;
self.btn1.alpha = 1.0f;
self.btn0.alpha = 1.0f;
}
else
{
self.btn3.center = self.btn0.center;
self.btn1.center = self.btn0.center;
self.btn2.center = self.btn0.center;
self.btn3.alpha = 0.0f;
self.btn1.alpha = 0.0f;
self.btn0.alpha = 0.0f;
}
The YES branch executes as expected but the NO branch executes as if the alphas get cleared immediately, even though the entire thing appears inside an animation block.
This is really simple stuff, and I can't see what may be wrong with it. Any help is appreciated.
Thanks!
WT
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden