4
A
回答
8
如果該部分的第一個單元格不再可見,則標題將會浮動。所以:
NSIndexPath *topCellPath = [[self.tableView indexPathsForVisibleRows] objectAtIndex:0];
if (topCellPath.row != 0)
{
// Header must be floating!
}
您可以通過滾動與scrollToRowAtIndexPath:atScrollPosition:animated:
指數路徑和UITableViewScrollPositionNone
滾動位置達到類似的效果 - 這不會滾動,如果在一節中的第一個單元格已經在屏幕上。
1
您可以先存儲節頭視圖的原始矩形。
headerView.originalPoint = [tableView rectForHeaderInSection:section].origin;
併發送scrollViewDidScroll:scrollView
消息到標題。
在你的頭視圖
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
BOOL isFloating = self.frame.origin.y > self.originalPoint.y;
if (isFloating) {
//DO what you want
}
}
1
這工作。
@implementation UITableView (rrn_extensions)
-(BOOL)rrn_isFloatingSectionHeaderView:(UITableViewHeaderFooterView *)view {
NSNumber *section = [self rrn_sectionForHeaderFooterView:view];
return [self rrn_isFloatingHeaderInSection:section.integerValue];
}
-(BOOL)rrn_isFloatingHeaderInSection:(NSInteger)section {
CGRect frame = [self rectForHeaderInSection:section];
CGFloat y = self.contentInset.top + self.contentOffset.y;
return y > frame.origin.y;
}
-(NSNumber *)rrn_sectionForHeaderFooterView:(UITableViewHeaderFooterView *)view {
for (NSInteger i = 0; i < [self numberOfSections]; i++) {
CGPoint a = [self convertPoint:CGPointZero fromView:[self headerViewForSection:i]];
CGPoint b = [self convertPoint:CGPointZero fromView:view];
if (a.y == b.y) {
return @(i);
}
}
return nil;
}
@end
0
該代碼適用於我。
- (BOOL)isSection0HeaderSticky {
CGRect originalFrame = [self.listTableView rectForHeaderInSection:0];
UIView *section0 = [self.listTableView headerViewForSection:0];
if (originalFrame.origin.y < section0.frame.origin.y) {
return YES;
}
return NO;
}
0
添加@ robdashnash的回答迅速端口
extension UITableView
{
func isFloatingSectionHeader(view:UITableViewHeaderFooterView)->Bool
{
if let section = section(for:view)
{
return isFloatingHeaderInSection(section:section)
}
return false
}
func isFloatingHeaderInSection(section:Int)->Bool
{
let frame = rectForHeader(inSection:section)
let y = contentInset.top + contentOffset.y
return y > frame.origin.y
}
func section(for view:UITableViewHeaderFooterView)->Int?
{
for i in stride(from:0, to:numberOfSections, by:1)
{
let a = convert(CGPoint.zero, from:headerView(forSection:i))
let b = convert(CGPoint.zero, from:view)
if a.y == b.y
{
return i
}
}
return nil
}
}
相關問題
- 1. 如何使節標題浮在UITableView中..
- 2. 是否可以通過UITableViewStylePlain在UITableView中禁用浮動標題?
- 3. UITableView節標題在更改標籤後浮動
- 4. 問題檢測是否已經的UITableView滾動至底部
- 5. UITableView:錨節標題
- 6. 檢測是否NSString的是浮點數
- 7. 檢測UITableView滾動
- 8. UITableView:節標識符問題
- 9. UITableView錯誤章節標題
- 10. UITableview:固定節標題
- 11. UITableView和觸摸節標題
- 12. 滾動UITableView標題?
- 13. 如何檢測css浮動項是否溢出到下一行?
- 14. MonoTouch - 檢測UITableView滾動
- 15. 檢查數字是否與Zend浮動
- 16. 檢測UIScrollView是否滾動
- 17. 訪問UITableView節標題標籤
- 18. 浮動[] ArrayList,無法檢查浮動[]是否包含在ArrayList
- 19. 檢測節點是否收到stdin
- 20. 如何檢測標籤節點是否不在場景中?
- 21. 浮動UITableView圖像?
- 22. tvOS 9.1 UITableView標題視圖不會浮動
- 23. UITableView將不會顯示浮動部分標題
- 24. 浮動標題,是否有比我更好的方法?
- 25. 當拖動節標題視圖時阻止UITableView滾動
- 26. 如何在顯示錶格後檢索UITableView節標題的標題?
- 27. 檢測是否UITableView的是beginUpdates/endUpdates狀態
- 28. 是否可以錨定表視圖標題(不是節標題)
- 29. jQuery動畫檢測是否動畫?
- 30. UITableView標題視圖動畫
謝謝,這作品!使用'scrollToRowAtIndexPath:atScrollPosition:animated:'不適用於我的情況,因爲該部分可能會摺疊並因此不包含一行。 – Meinhard
@meinhard是否在使用https://github.com/rob-nash/CollapsableTable? – 2017-06-16 09:28:19