滑动时,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

根据headerView位置改变headerView颜色(collectionView/tableview)的更多相关文章

  1. javascrip总结42:属性操作案例: 点击盒子,改变盒子的位置和背景颜色

    <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8& ...

  2. Android--ColorMatrix改变图片颜色

    前言 本篇博客讲解如何通过改变图片像素点RGB的值的方式,在Android中改变图片的颜色.在最后将以一个简单的Demo来作为演示. 本篇博客的主要内容: ColorMatrix 使用ColorMat ...

  3. 利用CSS3 filter:drop-shadow实现纯CSS改变图片颜色

    体验更优排版请移步原文:http://blog.kwin.wang/programming/css3-filter-drop-shadow-change-color.html 之前做项目过程中有时候遇 ...

  4. Android 改变字体颜色的三种方法

    在TextView中添加文本时有时需要改变一些文本字体的颜色,今天学到了三种方法,拿出来分享一下     1.在layout文件下的配置xml文件中直接设置字体颜色,通过添加android:textc ...

  5. [Xcode 实际操作]九、实用进阶-(17)使用CGBlendMode改变UIImage颜色,实现对图片进行混合着色

    目录:[Swift]Xcode实际操作 本文将演示如何使用CGBlendMode改变UIImage颜色,实现对图片进行混合着色. 在项目文件夹[DemoApp]上点击鼠标右键 ->[New Fi ...

  6. Android改变图片颜色的自定义控件

    效果如下: 理解:Xfermode的16总模式如图 第一步: package com.rong.activity; import com.rong.test.R; import android.con ...

  7. [JS9] document's bgColor改变背景颜色

    <HTML> <HEAD> <TITLE>设置背景颜色</TITLE> </HEAD> <BODY> <CENTER> ...

  8. OpenGL的glClearColor和glClear改变背景颜色

    OpenGL的glClearColor和glClear改变背景颜色 结合以下两个函数void glClearColor(GLclampf red,    GLclampf green, GLclamp ...

  9. collectionView/tableview刷新时关闭动画无效

    collectionView/tableview reloadSections/reloaddata时去掉动画无效时可以尝试使用 [UIView performWithoutAnimation:^{ ...

随机推荐

  1. 11.cadence.通孔类封装创建[原创]

    1.打开Pad Designer ---- ----- ---- ---- OK ------- ---- 回到Pad Designer internal:不管是几层板,中间层用这个就可以了: --- ...

  2. JavaScript高级程序设计之数据类型

    首先讲讲关于js文件放置的问题,如果把<script>放在head标签处,浏览器会先加载完该处的所有不使用defer属性的js文件再呈现页面的内容(浏览器在遇到body标签时才呈现内容), ...

  3. Qt之等待提示框(QTimer)

    简述 上节讲述了关于QPropertyAnimation实现等待提示框的显示,本节我们使用另外一种方案来实现-使用定时器QTimer,通过设置超时时间定时更新图标达到旋转效果. 简述 效果 资源 源码 ...

  4. UVa 11636 (注意读题) Hello World!

    这道题巨坑啊,样例中以-1结束输入的,所以我就天真的以为测试数据也是以-1结束输入的 其实人家原文中说: Input is terminated by a line containing a nega ...

  5. 了解Objective-C中NSAutoreleasePool使用方法

    本文的目的是来了解Objective-C中NSAutoreleasePool使用方法,Objective-C的Foundation库实际上是种运行级对象系统,与一般的对象语言,例如C++,Java不一 ...

  6. Qt 获取usb设备信息 hacking

    /************************************************************************** * Qt 获取usb设备信息 hacking * ...

  7. Android 系统开发学习杂记(转)

    http://blog.csdn.net/shagoo/article/details/6709430 > 开发环境1.安装 Eclipse 和 android-sdk 并解压安装2.Eclip ...

  8. Asp.net动态调用WebService

    Public Class WebServiceHelper #Region "InvokeWebService" '动态调用web服务 Public Shared Function ...

  9. ecshop 分类树全部显示

    1.在page_header.lbi文件中加入 $GLOBALS['smarty']->assign('categories',get_categories_tree()); // 保证首页页面 ...

  10. 剑指offer—第二章算法之二分查找(旋转数组的最小值)

    旋转数组的最小数字 题目:把一个数组最开始的若干元素搬到数组的末尾,我们称之为数组的旋转.输入一个递增排序的数组的一个旋转,输出旋转数组的最小元素.例如:数组{3,4,5,1,2}为{1,2,3,4, ...