我有一个名为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函数吗?
非常感谢您提前的任何帮助。