如何删除带有动画的uiview
how to remove uiview with animation
我使用以下代码添加了带有一些动画的 UIView
:
CGRect a = CGRectMake(10,10,295,460);
UIView *customView = [[UIView alloc]initWithFrame:a];
customView.tag=10;
[self.tableView addSubview:customView];
[UIView animateWithDuration:1.0
animations:
^{
customView.transform = CGAffineTransformMakeScale(1.0f, 1.0f);
}
];
当我尝试删除带动画的 UIView
时,动画似乎不起作用。视图只是在没有任何动画的情况下被删除。
这是我必须删除带有动画的 UIView
:
UIView *removeView=[self.tableView viewWithTag:10] ;
removeView .transform = CGAffineTransformMakeScale(1.0f, 1.0f);
[removeView removeFromSuperview];
[UIView animateWithDuration:1.5
animations:
^{
removeView .transform = CGAffineTransformMakeScale(0.0f, 0.0f);
}
];
我尝试在 [removeView removeFromSuperview]
前后放置 [UIView animateWithDuration:1.5 ...
块,但 none 给了我动画。请帮我解决这个问题。
[UIView animateWithDuration:1.5 animations:^ {
removeView.transform = CGAffineTransformMakeScale(0.0f, 0.0f);
} completion:^(BOOL finished) {
[removeView removeFromSuperview];
}];
尝试等到动画结束后再移除视图:
[removeView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:2.0];
一些变化:
UIView *removeView=[self.tableView viewWithTag:10] ;
removeView .transform = CGAffineTransformMakeScale(1.0f, 1.0f);
[removeView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1.5];
[UIView animateWithDuration:1.5
animations:
^{
removeView .transform = CGAffineTransformMakeScale(0.01f, 0.01f);
}
];
尝试将最终变换设置为小但非零的值。
试试这个,它对我有用:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.5f];
removeView.transform = CGAffineTransformMakeTranslation(removeView.frame.origin.x,1000.0f + (removeView.frame.size.height/2));
aview.alpha = 0;
[UIView commitAnimations];
参考以下来自 Apple 的示例。
[UIView transitionWithView:containerView
duration:0.2
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{ [fromView removeFromSuperview]; [containerView addSubview:toView]; }
completion:NULL];
以上代码为指定的容器视图创建了翻转过渡。在过渡的适当时间点,一个子视图被移除,另一个被添加到容器视图。这使得它看起来好像新视图与新子视图一起翻转到位,但实际上它只是使用新配置动画回到位的相同视图。
可能是您需要管理的动画类型。
参考:-
https://developer.apple.com/documentation/uikit/uiview/1622574-transition
我使用以下代码添加了带有一些动画的 UIView
:
CGRect a = CGRectMake(10,10,295,460);
UIView *customView = [[UIView alloc]initWithFrame:a];
customView.tag=10;
[self.tableView addSubview:customView];
[UIView animateWithDuration:1.0
animations:
^{
customView.transform = CGAffineTransformMakeScale(1.0f, 1.0f);
}
];
当我尝试删除带动画的 UIView
时,动画似乎不起作用。视图只是在没有任何动画的情况下被删除。
这是我必须删除带有动画的 UIView
:
UIView *removeView=[self.tableView viewWithTag:10] ;
removeView .transform = CGAffineTransformMakeScale(1.0f, 1.0f);
[removeView removeFromSuperview];
[UIView animateWithDuration:1.5
animations:
^{
removeView .transform = CGAffineTransformMakeScale(0.0f, 0.0f);
}
];
我尝试在 [removeView removeFromSuperview]
前后放置 [UIView animateWithDuration:1.5 ...
块,但 none 给了我动画。请帮我解决这个问题。
[UIView animateWithDuration:1.5 animations:^ {
removeView.transform = CGAffineTransformMakeScale(0.0f, 0.0f);
} completion:^(BOOL finished) {
[removeView removeFromSuperview];
}];
尝试等到动画结束后再移除视图:
[removeView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:2.0];
一些变化:
UIView *removeView=[self.tableView viewWithTag:10] ;
removeView .transform = CGAffineTransformMakeScale(1.0f, 1.0f);
[removeView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1.5];
[UIView animateWithDuration:1.5
animations:
^{
removeView .transform = CGAffineTransformMakeScale(0.01f, 0.01f);
}
];
尝试将最终变换设置为小但非零的值。
试试这个,它对我有用:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.5f];
removeView.transform = CGAffineTransformMakeTranslation(removeView.frame.origin.x,1000.0f + (removeView.frame.size.height/2));
aview.alpha = 0;
[UIView commitAnimations];
参考以下来自 Apple 的示例。
[UIView transitionWithView:containerView
duration:0.2
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{ [fromView removeFromSuperview]; [containerView addSubview:toView]; }
completion:NULL];
以上代码为指定的容器视图创建了翻转过渡。在过渡的适当时间点,一个子视图被移除,另一个被添加到容器视图。这使得它看起来好像新视图与新子视图一起翻转到位,但实际上它只是使用新配置动画回到位的相同视图。
可能是您需要管理的动画类型。
参考:- https://developer.apple.com/documentation/uikit/uiview/1622574-transition