Ios 为UITableView设置动画';页眉和页脚
我正在努力用动画制作删除tableview页眉/页脚内容的动画。我相信我可以对标题内容本身调用removeFromSuperview,或者只是将标题指定为nil,但我不知道如何设置动画。简单的动画块没有任何作用-如何淡入/淡出视图(本例中为标签)?我编写了一个示例,说明如何使用动画块完全删除标题视图Ios 为UITableView设置动画';页眉和页脚,ios,cocoa-touch,uitableview,animation,core-animation,Ios,Cocoa Touch,Uitableview,Animation,Core Animation,我正在努力用动画制作删除tableview页眉/页脚内容的动画。我相信我可以对标题内容本身调用removeFromSuperview,或者只是将标题指定为nil,但我不知道如何设置动画。简单的动画块没有任何作用-如何淡入/淡出视图(本例中为标签)?我编写了一个示例,说明如何使用动画块完全删除标题视图 [UIView beginAnimations:nil context:NULL]; [self.tableView setTableHeaderView:nil]; [UIView commitA
[UIView beginAnimations:nil context:NULL];
[self.tableView setTableHeaderView:nil];
[UIView commitAnimations];
当然,这假定此动画是在UITableViewController类内部调用的
仅仅从superview中删除header视图是行不通的,因为table视图不知道如何调整自身大小来填充以前的header视图。标题视图的设置会使表格视图以动画方式刷新自身
如果不起作用,请检查tableView实例的分配。我发现以下两个选项都可以正常工作: 选择1
[UIView animateWithDuration:0.15
delay:0.0
options: UIViewAnimationCurveEaseOut
animations:^{deleteLabel.alpha = 0;}
completion:nil];
选择2
[UIView beginAnimations:nil context:nil];
deleteLabel.alpha = 0.0;
[UIView commitAnimations];
这是完美的工作“原样”,我不关心动画
[myPrettyViewControllerInstance letUpdatePrettyViewNow];
[[self tableView] beginUpdates];
[[self tableView] setTableHeaderView:[myPrettyViewControllerInstance view]];
[[self tableView] endUpdates];
但如果我们不再需要它
[[self tableView] setTableHeaderView:nil];
这就是我们所需要的一切,真的(如果它没有消失-检查
[[self tableView] setTableHeaderView:nil];
我们不需要
[UIView beginAnimations:nil context:NULL];
[[self tableView] setTableHeaderView:nil];
[UIView commitAnimations];
不
不
noo..我最终得到了以下简单的解决方案。它为标题的删除设置了动画
[self.tableView beginUpdates];
self.tableView.tableHeaderView = nil;
[self.tableView endUpdates];
我知道WINSergey的回答中提到了这一点,但我发现他的解释有点混乱。我也有同样的问题,我想控制如何删除标题,以下是我的方法: 在ViewDidLoad时:
UIView *transView = [[UIView alloc] initWithFrame:CGRectMake(0.f, 0.f, 320.f, 200.f)];
transView.backgroundColor = [UIColor clearColor];
self.headerView = transView;
[transView release];
[self.tableView setTableHeaderView:self.headerView];
然后,当您需要删除标题时:
[UIView animateWithDuration:.3f
delay:.0f
options: UIViewAnimationOptionBeginFromCurrentState
animations:^{
self.headerView.frame = CGRectMake(0.0f, 0.0f, 320.f, 0.0f);
}
completion:^(BOOL finished) {
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:section] atScrollPosition:UITableViewScrollPositionTop animated:YES];
}];
我必须放两个动画才能让它工作
[UIView animateWithDuration:2.0f animations:^{
mylbl.alpha = 0.1 ;
} completion:^(BOOL finished) {
[UIView animateWithDuration:2.0f animations:^{
mylbl.alpha = 1.0 ;
}];
}];
如果有人这样做,我必须混合所有答案,因为它在
UITableView
中正常工作。简单地执行beginUpdates
和endUpdates
并没有为我添加动画。这样可以移除页脚,并且单元格可以随着动画而快速下降,而不是突然一跳
private func updateFooter(view : UIView?, size : CGFloat){
UIView.beginAnimations(nil, context: nil)
mainTableView.beginUpdates()
mainTableView.tableFooterView = view
mainTableView.tableFooterView?.frame.size.height = size
mainTableView.endUpdates()
UIView.commitAnimations()
}
是否使用UITableViewController、UITableViewDelegate或UITableViewDataSource实例或其他视图控制器类?如果使用UITableViewDataSource,则应使用tableView:(UITableView*)tableView标题ForHeaderSection:(NSInteger)节实际删除标题和tableView:(UITableView*)tableView TitleForFooterInstitution:(NSInteger)节以编程方式删除页脚。我使用的是tableView控制器。我只是想澄清一下,我想淡出表的页眉视图,而不是节标题,但它适用于页眉(不知道单元格)。我在最近的项目中使用了它,并且所有的都工作了。你能提供源代码吗?它不适用于插入表头视图。使用故事板和自动布局。视图只是出现。它不会在中动画。工作代码“-(void)updateAITrackerStatus{''AITracker*tracker=[[DataSingleton sharedSingleton]theAgenda]aiTracker];'if(tracker){[[u aiTrackerVC setTracker:tracker];[[u tableView beginUpdates];[self tableView]setTableHeaderView:[[u aiTrackerVC view]];[u tableView endUpdates];}否则{[[self tableView]setTableHeaderView:nil];}'对于遵循此操作的任何人来说,这只是一个小提示,上面的选项应该是UIViewAnimationOptionCurveEaseOut
[UIView animateWithDuration:2.0f animations:^{
mylbl.alpha = 0.1 ;
} completion:^(BOOL finished) {
[UIView animateWithDuration:2.0f animations:^{
mylbl.alpha = 1.0 ;
}];
}];
private func updateFooter(view : UIView?, size : CGFloat){
UIView.beginAnimations(nil, context: nil)
mainTableView.beginUpdates()
mainTableView.tableFooterView = view
mainTableView.tableFooterView?.frame.size.height = size
mainTableView.endUpdates()
UIView.commitAnimations()
}