2010-07-15 25 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