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
    
  • 相关阅读:
    详解log4j2(下)
    linux编译相关知识
    vi/vim正则表达式
    红黑树学习
    转行做程序员之前必须考虑的三件事
    工作十年,你为什么依然没有成为专家
    __sync_fetch_and_add
    STL容器的本质
    学习hash_map从而了解如何写stl里面的hash函数和equal或者compare函数
    c++ union学习
  • 原文地址:https://www.cnblogs.com/levy/p/gen-juheaderView-wei-zhi-gai-bianheaderView-yan-se.html
Copyright © 2011-2022 走看看