zoukankan      html  css  js  c++  java
  • 根据headerView位置改变headerView颜色(collectionView/tableview)

    滑动时,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
    
  • 相关阅读:
    控制语句
    (小程序)接收用户键盘输入
    运算符
    java doc形成注释文档
    linux中rz、sz命令,zip、unzip命令,sqlite3基本操作
    hash应用-加随机盐保存密码
    非对称/对称加密算法,hash算法
    自签名的应用--数字货币
    HTTPS原理
    Django中app的model相互引用问题
  • 原文地址:https://www.cnblogs.com/levy/p/gen-juheaderView-wei-zhi-gai-bianheaderView-yan-se.html
Copyright © 2011-2022 走看看