我很努力通過動畫去除tableview的頁眉/頁腳內容。我相信我可以在標題內容本身上調用removeFromSuperview,或者只將標題分配給nil,但我不知道如何爲此設置動畫。一個簡單的動畫塊不會做任何事情 - 如何淡入淡出視圖(在這種情況下是標籤)進/出?動畫UITableView的頁眉和頁腳
11
A
回答
24
我寫了一個例子,說明如何使用動畫塊完全刪除標題視圖。
[UIView beginAnimations:nil context:NULL];
[self.tableView setTableHeaderView:nil];
[UIView commitAnimations];
這當然假設這個動畫是在你的UITableViewController類中被調用的。
簡單地從超級視圖中刪除標題視圖不起作用,因爲表視圖不知道要調整自己的大小來填充過去是標題視圖。標題視圖的設置使表格視圖動畫刷新自身。
如果這不起作用,請檢查您的tableView實例的賦值。
1
我發現下面的兩個選項都工作正常:
選項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];
+2
對於任何在此之後的人,只需稍作說明,上面的選項應該是UIViewAnimationOptionCurveEaseOut – 2015-02-13 00:44:31
0
這是工作完美 「現況」,我不關心動畫
[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];
nop
[[self tableView] beginUpdates];
[[self tableView] setTableHeaderView:nil];
[[self tableView] endUpdates];
NOP
[[self tableView] setTableHeaderView:nil];
[[self tableView] reloadData];
野應..
8
我結束了以下簡單的解決方案。它動畫化了標題的刪除。
[self.tableView beginUpdates];
self.tableView.tableHeaderView = nil;
[self.tableView endUpdates];
我意識到這是在WINSergey的迴應中提到的,但我發現他的解釋有點混亂。
1
我有同樣的問題,我想控制的標題是如何去除,這裏是我的方法:
在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];
}];
0
我不得不放2個動畫來讓它工作。
[UIView animateWithDuration:2.0f animations:^{
mylbl.alpha = 0.1 ;
} completion:^(BOOL finished) {
[UIView animateWithDuration:2.0f animations:^{
mylbl.alpha = 1.0 ;
}];
}];
相關問題
- 1. 獲取UITableView頁眉/頁腳
- 2. UITableView:頁眉和頁腳視圖的繪畫行爲
- 3. UITableView頁眉/頁腳字體顏色
- 4. 動態頁眉和頁腳liferay
- 5. 頁眉和頁腳徽標
- 6. 粘性頁眉和頁腳
- 7. 頁眉和頁腳在
- 8. pdfkit頁眉和頁腳
- 9. 頁眉和頁腳衝突
- 10. 通用頁眉和頁腳
- 11. PHP頁眉和頁腳
- 12. 頁眉和頁腳XSL FO
- 13. NSCollectionView與頁眉和頁腳
- 14. ReactJS頁眉和頁腳
- 15. 固定頁眉和頁腳
- 16. listview與頁眉和頁腳
- 17. iText 5頁眉和頁腳
- 18. FPDF頁眉和頁腳
- 19. 頁眉和頁腳佈局
- 20. TraceListener頁眉和頁腳
- 21. 剝離頁眉和頁腳
- 22. 我如何隱藏UITableView控制器的頁眉和頁腳?
- 23. iOS UITableView:空的頁眉和頁腳高度?
- 24. 提取頁面的頁眉和頁腳
- 25. UITableView:並列行,頁眉和頁腳插入/刪除
- 26. 如何從UITableView中刪除頁眉和頁腳空間?
- 27. famo.us:我可以爲頁眉頁腳佈局的頁眉/頁腳高度設置動畫效果嗎?
- 28. Cognos頁眉/頁腳
- 29. 頁腳到頁眉
- 30. 網站優化和頁眉/頁腳頁
你使用UITableViewController,UITableViewDelegate或UITableViewDataSource實例或其他視圖控制器類嗎?如果您使用的是UITableViewDataSource,則應該使用tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)部分以實際刪除標題和tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)部分以編程方式刪除頁腳。 – 2012-04-23 23:05:50
我正在使用tableview控制器。只是爲了澄清,我想淡出表格的標題視圖,而不是部分標題 – 2012-04-23 23:11:19