美文网首页
iOS 监听tableVIew的偏移量,获取cell的Frame

iOS 监听tableVIew的偏移量,获取cell的Frame

作者: 小白进城 | 来源:发表于2017-09-20 12:22 被阅读510次

监听tableVIew的偏移量

1、添加监听

[self.tableView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil];

2、监听的处理

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
    if ([keyPath isEqualToString:@"contentOffset"]){
        CGPoint offset = [change[NSKeyValueChangeNewKey] CGPointValue];
    }
}

3、移除监听

[self.tableView removeObserver:self forKeyPath:@"contentOffset" context:nil];

获取子控件的Frame

1、section的frame

- (CGRect)rectForSection:(NSInteger)section;

说明:包括了header、 footer和其所有cell

2、cell的frame

- (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath;

3、获取header的frame

- (CGRect)rectForHeaderInSection:(NSInteger)section;

4、获取footer的frame

- (CGRect)rectForFooterInSection:(NSInteger)section;

相关文章

网友评论

      本文标题:iOS 监听tableVIew的偏移量,获取cell的Frame

      本文链接:https://www.haomeiwen.com/subject/tltosxtx.html