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