2013-11-20 15 views
1

我有一個UIView動畫與的iOS - [UIView的setAnimationDidStopSelector:@selector(animationDidStop:成品::)背景]所謂太快

[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)] 

出於某種原因,animationDidStop:finished:context:動畫結束前被調用。 任何想法? (上iOS7模擬器測試)

代碼:

-(void)checkForAndRemoveTable { 

//The animation should fade to 0 then remove itself from it's superview at the end. 

if (tableViewController.view.superview != nil) { 

    [UIView beginAnimations:@"dismissTable" context:NULL]; 
    [UIView setAnimationDuration:0.5]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)]; 
    tableViewController.view.alpha = 0; 
    [UIView commitAnimations]; 

} 


} 


-(void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { 

if ([animationID isEqualToString:@"dismissTable"]) { 

    [tableViewController.view removeFromSuperview]; 
} 


} 

回答

2

使用基於塊的動畫試試看。畢竟,蘋果公司已經建議這樣做,因爲iOS的4

if (tableViewController.view.superview != nil) { 
    [UIView animateWithDuration:0.5 delay:0.0 options:kNilOptions animations:^{ 
     tableViewController.view.alpha = 0; 
    } completion:^(BOOL finished) { 
     [tableViewController.view removeFromSuperview]; 
    }]; 
} 

或者,也可能是這種行爲是從功能的濫用到來。例如,如果發生快速連續多次調用動畫功能的事件,則可能導致動畫回調的時機關閉。 (請參閱下面的註釋)

+0

同樣的問題,當我用這個,但我找到了原因!看起來我錯誤地(從另一個函數)調用包含我的動畫兩次的函數。請用「請參閱解決方案的意見」更新您的答案。謝謝。 – Zigglzworth

0

在iOS 4及更高版本中,使用基於塊的動畫方法。 (推薦) - >蘋果文檔

使用[UIView animateWithDuration:animations:completion:]方法