UIView使用块动画方法实现滑入动画,但无法实现滑出动画。

6

我有一个名为geopointView的UIView。当按下按钮(myButton)时,我希望在主视图框架上通过动画将此UIview滑入。如果再次按下myButton,则UIView应滑出框架。myButton调用以下方法“optionsCalled”

-(void) optionsCalled
{
if (![[self.view subviews] containsObject:geopointView] &&checkForGeopointViewAnimation ==0) {

        [self.view addSubview:geopointView];
        geopointView.frame = CGRectMake(0,430,320,30);
        [UIView animateWithDuration:0.3f 
                         animations:^{
                             geopointView.frame = CGRectMake(0, 350, 100, 80);
                         }
                         completion:^(BOOL finished){
                             checkForGeopointViewAnimation = 1 ;
                         }];

    }
    if ([[self.view subviews] containsObject:geopointView] && checkForGeopointViewAnimation ==1)
    {

        geopointView.frame = CGRectMake(0, 350, 100, 80);
        [UIView animateWithDuration:0.3f 
                         animations:^{
                             geopointView.frame = CGRectMake(0,430,320,30);
                         }
                         completion:^(BOOL finished){
                             checkForGeopointViewAnimation = 0 ;
                         }];

        [geopointView removeFromSuperview];

    }

}

这里定义了一个全局变量checkForGeopointViewAnimation,以确保滑入和滑出不会同时执行。

这段代码存在的问题是,UIview可以动画地滑入,但无法动画地滑出。它只是从主帧中消失。我需要在这里使用任何时间延迟调用添加和删除UIview函数吗?

非常感谢您提前的任何帮助。

2个回答

5
在动画完成后尝试使用[geopointView removeFromSuperview];

1
@amol_subhedar:请投票支持所有帮助过你的答案,作为感激之情的象征。 - visakh7

4
也许你需要在完成块中调用[geopointView removeFromSuperview];

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接