覆盖removeFromSuperview

时间:2014-11-03 13:51:55

标签: ios xcode uiview

我正在尝试为我创建的自定义视图覆盖removeFromSuperview。该视图旨在包含一个UIActivityIndi​​catorView,并设法成功地为其外观设置动画,覆盖initWithFrame方法。现在我想覆盖它的removeFromSuperview,在其中添加淡出动画,以便从视图控制器我可以简单地调用[self.loadingView removeFromSuperview];不幸的是,在没有动画的情况下删除了loadingView,可能是因为[super removeFromSuperview];我在覆盖时需要打电话。这是我正在使用的代码,有没有办法可以修复它?

-(void)removeFromSuperview
{
[super removeFromSuperview];
[UIView animateWithDuration:0.5
                 animations:^{self.alpha = 0.0;}
                 completion:^(BOOL finished){[self removeFromSuperview];}];
}

1 个答案:

答案 0 :(得分:0)

尝试将[super removeFromSuperview]放入动画的完成块中:

-(void)removeFromSuperview
{
    [UIView animateWithDuration:0.5
             animations:^{self.alpha = 0.0;}
             completion:^(BOOL finished){[super removeFromSuperview];}];

}