我有一种方法可以为其中一个子视图设置动画UIWindow
,然后将其从UIWindow
使用中删除removeFromSuperview
。但是当我放在removeFromSuperview
动画块之后,动画永远不会显示,因为在动画播放之前removeFromSuperview
删除了UIView
:-(UIWindow
我怎样才能延迟removeFromSuperview
动画先播放,然后删除子视图?我[NSThread sleepForTimeInterval:1];
在动画块之后尝试过,但那没有有预期的效果,因为动画出于某种原因也睡着了。
我的这种方法的代码:
- (void) animateAndRemove
{
NSObject *mainWindow = [[UIApplication sharedApplication] keyWindow];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.8];
UIView *theView = nil;
for (UIView *currentView in [mainWindow subviews])
{
if (currentView.tag == 666)
{
currentView.backgroundColor = [UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:0.0];
theView = currentView;
}
}
[UIView setAnimationTransition: UIViewAnimationTransitionNone forView:theView cache:YES];
[UIView commitAnimations];
//[NSThread sleepForTimeInterval:1];
[theView removeFromSuperview];
}