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"]) {
CGFloat offset_Y = self.myOrderTableView.contentOffset.y;
CGFloat cellAddressHeight = 50.0f;
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;
}];
}
}
}