Giter Site home page Giter Site logo

hybmasonryautocellheight's Introduction

HYBMasonryAutoCellHeight

A very helpful category for calculating the height of cell automatically.

##说明 在github没有找到基于Masonry自动计算行高的库,倒是找到了使用xib和storyboard在添加约束来自动计算行高的库,如: UITableView-FDTemplateLayoutCell

本人非常推崇Masonry来实现代码的自动布局,因此项目中都是使用Masonry布局的,为了自动计算行高,决定写一个扩展,以达到自动计算的效果,如此一来,开发者不用再关心那些非固定行高的cell的动态计算问题了。

##使用 只需要在UITableView的代理方法中调用:

/**
 * 通过此方法来计算行高,需要在config中调用配置数据的API
 *
 * @param indexPath 必传,对应的indexPath
 * @param confi     必须要实现,且需要调用配置数据的API
 *
 * @return 计算的行高
 */
+ (CGFloat)hyb_heightForIndexPath:(NSIndexPath *)indexPath config:(HYBCellBlock)config;

调用方式类似如下:

- (CGFloat)tableView:(nonnull UITableView *)tableView heightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
  HYBNewsModel *model = nil;
  if (indexPath.row < self.dataSource.count) {
    model = [self.dataSource objectAtIndex:indexPath.row];
  }

  return [HYBNewsCell hyb_heightForIndexPath:indexPath config:^(UITableViewCell *sourceCell) {
    HYBNewsCell *cell = (HYBNewsCell *)sourceCell;
    
    // 配置数据
    [cell configCellWithModel:model];
  }];
}

具体使用和具体API说明,请参考Demo!

#Versions

  • 1.0.0 -* 增加缓存API
  • 2.0.1 -* 增加hyb_lastViewsInCell,当不确定哪个是最后一个时,可以使用此数组属性

##作者相关

个人博客地址:http://101.200.209.244.com/
CSDN博客地址:http://blog.csdn.net/woaifen3344
个人常用邮箱:[email protected]

##博文讲解

Masonry自动计算行高

##致谢 感谢UITableView-FDTemplateLayoutCell的作者sunnyxx给了我灵感,这才有现在的基于Masonry版本的自动计算行高的开源库。 感谢所有使用本开源库的开发者,感谢你们的使用和反馈。

##关注我

如果在使用过程中遇到问题,或者想要与我交流,可加入有问必答QQ群:324400294

关注微信公众号:iOSDevShares

关注新浪微博账号:标哥Jacky

##License MIT

hybmasonryautocellheight's People

Contributors

coderjackyhuang avatar wenbingzuo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hybmasonryautocellheight's Issues

你好 ,很不错,很棒

本我我也是喜欢用代码的,这个自动计算我是我想干的事,无奈看不懂masonry内部的逻辑,runtime也不行,我真的不懂,你是怎么发现指定cell中最后一个试图就可以计算高度了 呢?打死我,我也想不到,我的想法是masonry其实是基于apple的autolayout,然后布局完成以后,应该可以通过contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize 来计算得到,但是事实 算不出高度,有点纳闷,难道说masonry布局以后,cell并没有添加约束吗?应该 都添加了把。

还有个就是 ios8 以后,tableview的cell高度不在缓存,每次滑动都会重新计算,所以希望还是做个缓存高度的机制吧。

pod install error

$ pod install
Analyzing dependencies
[!] CocoaPods could not find compatible versions for pod "Masonry":
  In snapshot (Podfile.lock):
    Masonry (= 1.1.0)

  In Podfile:
    HYBMasonryAutoCellHeight (~> 2.0.1) was resolved to 2.0.1, which depends on
      Masonry (~> 0.6)

demo运行出现高度问题

f7793848-24c3-4c6e-99b9-9d6bd69ec630

运行demo 出现lastview 距离cell底部 高度不一致的情况。。。

iPhone6s 9.2 模拟器

(图片发不上来。。)

cocoapods error

[!] Unable to satisfy the following requirements:

  • Masonry required by Podfile
  • Masonry (= 1.0.2) required by Podfile.lock
  • Masonry (~> 0.6) required by HYBMasonryAutoCellHeight (0.0.1)

加载一个对象时候报错

在一个tableview显示一个对象的详细时候,如果对象是nil,那就崩溃,在

  • (CGFloat)hyb_heightForTableView:(UITableView *)tableView
    config:(HYBCellBlock)config
    cache:(HYBCacheHeight)cache
    必须要判断一下是否为空

if(self.info==nil)
{
return @{kHYBCacheUniqueKey:@"uniq",kHYBRecalculateForStateKey:@(YES),kHYBCacheStateKey:@"cache"};
}

        return @{kHYBCacheUniqueKey:[NSString stringWithFormat:@"%@",self.info.UrlAvatar],kHYBRecalculateForStateKey:@(NO),kHYBCacheStateKey:self.info.UrlAvatar};

计算高度错误

我发现如果一个label底部距离10的地方有一个按钮用来展开文字,这个按钮是隐藏的,当文字高度大于40时候,按钮显示,点击按钮文字进行展开或者收缩的效果,发现按钮展示的时候返回的高度是0的,请问要怎么解决?

行高计算不准的bug

有一个bug,在我项目中我使用了你的这个库,发现自动计算行高的时候,在文本特别多的时候,iPhone6s以上都计算的不对,cell与cell之间会有空隙,iPhone5s好像没事

TableView cell 点击有个默认选中颜色没有了....

TableView cell 点击有个默认选中颜色没有了,

  • (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
    // 刚选中又马上取消选中,格子不变色
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.