tabeleView 获取某个cell的高度(cell高度是动态计算的)。

可以直接使用:

CGRect frame = [tableView rectForRowAtIndexPath:indexPath];

但是需要注意的是它比较费资源,如果用kvo监听tableview的高度的方法里并且获取这个frame,直接崩溃。

- (void)configureActions{
    [self.myOrderTableView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:NULL];
}

- (void)observeValueForKeyPath:(NSString *)keyPath
                      ofObject:(id)object
                        change:(NSDictionary<NSKeyValueChangeKey,id> *)change
                       context:(void *)context{
    
    if ([keyPath isEqualToString:@"contentOffset"]) {
        
        //DLog(@"contentOffset is changed! new = %@",[change valueForKey:NSKeyValueChangeNewKey]);
        CGFloat offset_Y = self.myOrderTableView.contentOffset.y;
        //DLog(@" %@",@(offset_Y));
        CGFloat cellAddressHeight = 50.0f; //[self.myOrderTableView rectForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]].size.height;
        if (offset_Y > cellAddressHeight && self.addressTipsHidden == YES) { //设置显示
            self.addressTipsHidden = NO;
            [UIView animateWithDuration:0.3 animations:^{
                self.addressTipsLabel.alpha = 1;
            }];
        }else if(offset_Y < cellAddressHeight && self.addressTipsHidden == NO){ //设置隐藏
            self.addressTipsHidden = YES;
            [UIView animateWithDuration:0.3 animations:^{
                self.addressTipsLabel.alpha = 0;
            }];
        }
    }
}