我正在动画UIView(alpha)属性,我想在动画完成后我可以从超级视图中删除它.
-(void) hideOverlayView { [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:1.0]; [topView setAlpha:0]; [UIView commitAnimations]; }
一种选择是使用带延迟选项的performSelector,但是有更紧凑的方法吗?
更新1:
[UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:1.0]; [UIView setAnimationDelegate:topView]; [UIView setAnimationDidStopSelector:@selector(removeFromSuperview)]; [topView setAlpha:0]; [UIView commitAnimations];
解决方法
直接从
UIView docs
[UIView animateWithDuration:0.2 animations:^{view.alpha = 0.0;} completion:^(BOOL finished){ [view removeFromSuperview]; }];
或者在您的具体情况中:
[UIView animateWithDuration:1.0 animations:^{topView.alpha:0.0;} completion:^(BOOL finished){ [topView removeFromSuperview]; }];