1
我試圖從屏幕上以動畫模式移除超級視圖中的視圖。但是,在動畫應該結束之後,當我添加removeFromSuperview
調用時,視圖根本不會生成動畫,而是立即從屏幕消失。
那麼爲什麼沒有動畫時,我將[[self pickerView] removeFromSuperview];
添加到下面的方法?當它從超級視圖中移除時,視圖不是動畫
- (void) slidePickerOutView
{
[UIView beginAnimations:@"slidePickerOutView" context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.2];
[UIView setAnimationDidStopSelector:@selector(slidePickerOutViewEnded:finished:context:)];
CGRect r = CGRectMake(0, 480, 320, 244);
[[self pickerView] setFrame:r];
[UIView commitAnimations];
}
- (void) slidePickerOutViewEnded:(NSString *)id finished:(BOOL) finished context:(void *) context
{
//Stop observing the 'Done' button
[[self pickerView] removeObserver:self forKeyPath:@"valueSelectDone"];
[[self pickerView] removeObserver:self forKeyPath:@"selectedValue"];
[[self pickerView] removeFromSuperview];
[self setPickerView:nil];
}
你是說,如果你註釋掉與「removeFromSuperview」行,那麼動畫的作品?那會很奇怪。你有沒有嘗試過:設置一個更長的animationDuration,或者檢查委託方法中的「完成」值?不是說這些中的任何一個都會導致你描述的問題,但可能會產生更多的信息。 – Felixyz 2010-02-22 23:13:58
事實上,當我註釋掉'removeFromSuperview'這一行時,動畫就起作用了。在動畫開始之前,視圖立即從視圖中移除。通過KVO觀察動畫視圖,因此可以看到removeObserver行,但我不認爲這些行對這個問題很重要。 – Oysio 2010-02-23 08:15:11