animated UIButtons are clickable at destination before they reach destination
I have a UIView that contains a couple UIButtons that I am animating from offscreen to onscreen. I find that the region where they are heading is clickable before they reach it. The animation is pretty simple, so I'm wondering if there is something obvious that I am missing in terms of telling the code to not treat the button as if it is at the final destination (I'm not sure if that is supposed to be the expected behavior and the animation is purely a visual while the clickable region is instantaneously at the destination; I wouldn't expect it to be).
Here is the code I use to animate it. It's basically switching out 开发者_JAVA百科a sub panel and bringing back a main panel with buttons:
// switch back to main abilities panel
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: kFadeInTime];
CGRect rect = CGRectMake(
480.0f,
mAbilities.mSubPanel.frame.origin.y,
mAbilities.mSubPanel.frame.size.width,
mAbilities.mSubPanel.frame.size.height);
mAbilities.mSubPanel.frame = rect;
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: kFadeInTime];
[UIView setAnimationDelay: kFadeInTime];
rect = CGRectMake(
kAbilitiesBorderX,
mAbilities.mPanel.frame.origin.y,
mAbilities.mPanel.frame.size.width,
mAbilities.mPanel.frame.size.height);
mAbilities.mPanel.frame = rect;
[UIView commitAnimations];
As a workaround you can disable user interaction with your panel before animations and reenable it when animation finishes:
// Animation compete handler
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context{
mAbilities.mSubPanel.userInteractionEnabled = YES;
}
// Animating panel
mAbilities.mSubPanel.userInteractionEnabled = NO;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: kFadeInTime];
[UIView setAnimationDelegate: self];
CGRect rect = CGRectMake(
480.0f,
mAbilities.mSubPanel.frame.origin.y,
mAbilities.mSubPanel.frame.size.width,
mAbilities.mSubPanel.frame.size.height);
mAbilities.mSubPanel.frame = rect;
[UIView commitAnimations];
If you're targeting iOS4 you can (and as specs say should) use block-based animation api:
[UIView animateWithDuration:5.0f delay:0.0f options:UIViewAnimationOptionLayoutSubviews
animations:^(void){
CGRect rect = CGRectMake(
480.0f,
mAbilities.mSubPanel.frame.origin.y,
mAbilities.mSubPanel.frame.size.width,
mAbilities.mSubPanel.frame.size.height);
mAbilities.mSubPanel.frame = rect;
}
completion:NULL
];
While animating using blocks user interaction is disabled by default - you can enable it by setting UIViewAnimationOptionAllowUserInteraction
flag in options parameter:
... options:UIViewAnimationOptionLayoutSubviews | UIViewAnimationOptionAllowUserInteraction ...
精彩评论