以下是我的代码,用于在子视图上添加表格时显示一些淡入淡出效果。问题是代码第一次起作用。添加表格后,当我点击关闭时,删除子视图按钮表。但是当我按下按钮再次添加表时子视图淡入淡出效果不起作用
double delayInSeconds2 = 0.1;
dispatch_time_t popTime2 = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds2 * NSEC_PER_SEC));
dispatch_after(popTime2, dispatch_get_main_queue(), ^(void){
self.otlTableRightView.frame=CGRectMake(100, 68, 300, 378);
[self.otlTableRightView setAlpha:0.0];
[self.otlRightFromView addSubview:self.otlTableRightView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.2];
self.otlTableRightView.frame=CGRectMake(43, 68, 300, 378);
[UIView commitAnimations];
[UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
[self.otlTableRightView setAlpha:0.0];
}completion:^(BOOL done){
}];
});
我正在使用
[self.otlTableRightView removeFromSuperview];
从子视图中删除我的表
答案 0 :(得分:1)
如果你想重复动画,你不应该removeFromSuperview
你的子视图!然后所有的重复方法都没关系。
对于这种行为,您也可以考虑更简单的解决方案:
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveEaseInOut
animations:^{
[self.otlTableRightView setAlpha:0.0];
}
completion:^(BOOL done){
[self.otlTableRightView setAlpha:2.0];
}];
如您所见,您可以添加多个参数。
答案 1 :(得分:0)
要删除具有淡入淡出效果的表视图,请尝试此操作。希望它可以正常工作。
> [UIView animateWithDuration:1.0
> delay:0.0
> options: UIViewAnimationOptionCurveEaseInOut
> animations:^{
> [self.otlTableRightView setAlpha:0.0];
> }
> completion:^(BOOL done){
> [self.otlTableRightView removeFromSuperview];
> }];
答案 2 :(得分:0)
经过一番搜索,最后我发现了一些适用于我的情况。在这里, otlTableRightView 是我的 UItableView
的出口 self.otlTableRightView.alpha = 0;
[UIView beginAnimations:@"fade in" context:nil];
[UIView setAnimationDuration:2.0];
self.otlTableRightView.alpha = 1.0;
[UIView commitAnimations];