用kvo监听TableViewCell图片大小变化

来源:互联网 发布:轻淘客插件 mac 编辑:程序博客网 时间:2024/06/04 18:13

使用三方SDWebImage, 使用sd_setImageWithUrl,设置占位图片,当TableViewCell上的图片没有刷新出来的时候,保证其位置不会被占用。
eg. [cell.titltImageView sd_setImageWithURL:[NSURL URLWithString:car.newsImage] placeholderImage:[UIImage imageNamed:@”zhanwei2_1”]];
//用kvo监听
方法:重点内容
static void *imageViewFrameKey = &imageViewFrameKey;

  • (void)observeValueForKeyPath:(NSString )keyPath ofObject:(id)object change:(NSDictionary )change context:(void *)context;
  • eg:
  • (void)observeValueForKeyPath:(NSString )keyPath ofObject:(id)object change:(NSDictionary )change context:(void *)context
    {
    if (context == imageViewFrameKey) {

    //此时监听到imageView的frame发生变化,改成自定义的frame值UIImageView *imageView = (UIImageView *)object;CGRect newRect = CGRectMake(6, 4, 82, 51);if (!CGRectEqualToRect(imageView.frame, newRect)) {    imageView.frame = newRect;}

    } else {
    [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
    }
    }重点内容

0 0
原创粉丝点击