UIView animation only animating some of the things I ask it to
Posted
by Ben
on Stack Overflow
See other posts from Stack Overflow
or by Ben
Published on 2010-03-24T08:17:10Z
Indexed on
2010/03/24
8:23 UTC
Read the original article
Hit count: 374
I have a series of (say) boxes on the screen in a row, all subviews of my main view. Each is a UIView. I want to shift them all left and have a new view also enter the screen from the right in lockstep. Here's what I'm doing:
// First add a dummy view offscreen
UIView * stagingView = /* make this view, which sets up its width/height */
CGRect frame = [stagingView frame];
frame.origin.x = /* just off the right side of the screen */;
[stagingView setFrame:frame];
[self stagingView];
And then I set up animations in one block for all of my subviews (which includes the one I just added):
[UIView beginAnimations:@"shiftLeft" context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(_animationDidStop:context:)];
[UIView setAnimationDuration:0.3];
for (UIView * view in [self subviews]) {
CGRect frame = [view frame];
frame.origin.x -= (frame.size.width + viewPadding);
[view setFrame:frame];
}
[UIView commitAnimations];
Here's what I expect: The (three) views already on screen get shifted left and the newly staged view marches in from the right at the same time.
Here's what happens: The newly staged view animates in exactly as expected, and the views already on the screen do not appear to move at all! (Or possibly they jump without animation to their end locations).
And! If I comment out the whole business of creating the new subview offscreen... the ones onscreen do animate correctly!
Huh?
(Thanks!)
© Stack Overflow or respective owner