有人能告诉我为什么这段代码没有删除正在动画的子视图吗?视图堆积起来,第二次关闭视图时,它不会动画,现在有两个带有标签 99 的 subView 实例。第一次没有发布。
for (UIView *subview in [self.smallView subviews]) {
NSLog(@"view:%@",subview);
if (subview.tag == 99) {
[UIView animateWithDuration:.5
animations:^{
subview.alpha = 0;
}
completion:^(BOOL finished){
subview.alpha = 0;
[subview removeFromSuperview];
}];
}
}
这是我添加子视图的方法,viewVC 是 ViewController 子类,而 smallView 是我添加地图的位置,并且是所有视图的容器。
@property (nonatomic, retain) CustomViewController *viewVC;
viewVC = [self.storyboard instantiateViewControllerWithIdentifier:@"VIEWVC"];
viewVC.view.frame = CGRectMake(20, 20, 280, 371);
viewVC.view.layer.cornerRadius = 15;
viewVC.view.tag = 99;
viewVC.view.alpha = 0;
[self.smallView addSubview:viewVC.view];
[UIView animateWithDuration:.5
animations:^{
viewVC.view.alpha = 1;
}
completion:^(BOOL finished){
viewVC.view.alpha = 1;
}];