您的位置:首页 > 其它

根据headerView位置改变headerView颜色(collectionView/tableview)

2016-10-27 20:37 274 查看
滑动时,tableview中的headerView 的frame不断改变,collectionView的headerView的center不断改变.
so
tableview:

-(void)setFrame:(CGRect)frame{    [super setFrame:frame];    CGRect rect =  [self.superview convertRect:frame toView:[UIApplication sharedApplication].keyWindow];    if (rect.origin.y > 65 && rect.size.height > 0 && ![self.backgroundColor isEqual:[UIColor whiteColor]]) {        [self setBackgroundColor:[UIColor whiteColor]];    }else if(rect.origin.y < 65 && rect.size.height > 0 && ![self.backgroundColor isEqual:UIColorFromRGB(0xff3333)]){        [self setBackgroundColor:UIColorFromRGB(0xff3333)];    }}

collectionView:

#import "CollectionReusableView.h"@interface CollectionReusableView(){    CGFloat centerY;}@end@implementation CollectionReusableView-(void)setFrame:(CGRect)frame{    [super setFrame:frame];    centerY = self.frame.origin.y + self.frame.size.height/2.0;}-(void)setCenter:(CGPoint)center{    [super setCenter:center];    if (center.y < centerY + 1  && ![self.backgroundColor isEqual:[UIColor whiteColor]]) {        [self setBackgroundColor:[UIColor whiteColor]];    }else if(center.y > centerY + 1   > 0 && ![self.backgroundColor isEqual:[UIColor redColor]]){        [self setBackgroundColor:[UIColor redColor]];    }}@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: