我有一个叫做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功能时有延迟?
感谢您提前提供任何帮助
答案 0 :(得分:5)
动画完成后尝试[geopointView removeFromSuperview];
答案 1 :(得分:4)
也许您需要在完成版块中调用[geopointView removeFromSuperview];
?