iOS滚动视图tableview,collectionviewiOS 开发每天分享优质文章iOS Developer

关于tableView的headerView和footerVie

2016-04-12  本文已影响1271人  蒋昉霖

在设置tableView的headerView和footerView的页面的时候,正常设置会在5s上出现页面出不来的问题

我最开始查看了出来的先后顺序,发现在5s上面你得把设置header和footer的代码放到viewDidAppear里面,才能正常显示,但是这个时候footer没问题,但是haeder会在页面出现的时候不显示,然后在一闪从上往下出来header,这个产品如果没要求的话是可以的

但是这样还是不是很好,查阅了一些资料,发现一个东西
你只需要设置

footer.autoresizingMask = UIViewAutoresizingFlexibleWidth;
header.autoresizingMask = UIViewAutoresizingFlexibleWidth;

只需要加这行代码就好了...这个属性是自动布局之前出的布局的属性,现在用的很少了,但是老是出现莫名其妙的bug....

附上这个属性的参数吧

enum {
   UIViewAutoresizingNone                 = 0, // 不调整
   UIViewAutoresizingFlexibleLeftMargin   = 1 << 0, // 自动调整与superView的右边距离,保证与superView左边的距离不变。
   UIViewAutoresizingFlexibleWidth        = 1 << 1, // 自动调整自己的宽度,保证与superView左边和右边的距离不变。
   UIViewAutoresizingFlexibleRightMargin  = 1 << 2, // 自动调整与superView的右边距离,保证与superView左边的距离不变。
   UIViewAutoresizingFlexibleTopMargin    = 1 << 3, // 自动调整与superView底部的距离,也就是说,与superView顶部的距离不变。
   UIViewAutoresizingFlexibleHeight       = 1 << 4, // 自动调整自己的高度,保证与superView顶部和底部的距离不变。
   UIViewAutoresizingFlexibleBottomMargin = 1 << 5 // 自动调整与superView顶部的距离,保证与superView底部的距离不变。
};

这几个属性是可以组合的,比如

footer.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

好了,自己摸索着试试吧

上一篇下一篇

猜你喜欢

热点阅读