2010-07-15 46 views
1

我有一个UIView,其中包含一对UIButtons,我正在从屏幕外移动到屏幕上。我发现他们前往的区域在它们到达之前是可点击的。这个动画非常简单,所以我想知道是否有什么明显的东西在我告诉代码不把它看作是最终目的地的时候丢失了(我不确定是否应该这样做)是预期的行为,动画纯粹是一种视觉效果,而可点击区域即时在目的地;我不希望它是)。动画UIButtons可以在目标点击前到达目的地

以下是我用来为其设置动画的代码。这基本上切换出一个子面板,并带回带有按钮的主面板:

// 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];  

回答

1

作为一种变通方法,您可以禁用带有动画之前,你的面板用户交互和重新启用它,当动画完成:

// 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]; 

如果你的目标的iOS4你可以(和规格应该说)使用基于块的动画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 
    ]; 

在使用块动画的用户交互被禁用默认情况下 - 您可以通过在选项参数中设置UIViewAnimationOptionAllowUserInteraction标志来启用它:

... options:UIViewAnimationOptionLayoutSubviews | UIViewAnimationOptionAllowUserInteraction ... 
+0

感谢您的建议。你碰巧知道我所经历的是预期的行为吗?我编码的动画是否应该以这种方式工作,事件捕获在目的地已经处于活动状态? – Joey 2010-07-15 16:40:54