美文网首页
代码片段合集

代码片段合集

作者: _风雨 | 来源:发表于2018-01-14 15:37 被阅读5次

UIScrollView scroll change background color

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

// horizontal
CGFloat maximumHorizontalOffset = scrollView.contentSize.width - CGRectGetWidth(scrollView.frame);
CGFloat currentHorizontalOffset = scrollView.contentOffset.x;

// percentages
CGFloat percentageHorizontalOffset = currentHorizontalOffset / maximumHorizontalOffset;

NSLog(@"content offfset: %f", percentageHorizontalOffset);

if (percentageHorizontalOffset < 0.333333) {
    bgView.backgroundColor = [self fadeFromColor:self.colorArray[0] toColor:self.colorArray[1] withPercentage:percentageHorizontalOffset*3];
} else if (percentageHorizontalOffset >= 0.333333 && percentageHorizontalOffset < 0.666667) {
    bgView.backgroundColor = [self fadeFromColor:self.colorArray[1] toColor:self.colorArray[2] withPercentage:(percentageHorizontalOffset-0.333333)*3];
} else if (percentageHorizontalOffset >= 0.666667) {
    bgView.backgroundColor = [self fadeFromColor:self.colorArray[2] toColor:self.colorArray[3] withPercentage:(percentageHorizontalOffset-0.666667)*3];
}

}

- (UIColor *)fadeFromColor:(UIColor *)fromColor toColor:(UIColor *)toColor withPercentage:(CGFloat)percentage {
// get the RGBA values from the colours
CGFloat fromRed, fromGreen, fromBlue, fromAlpha;
[fromColor getRed:&fromRed green:&fromGreen blue:&fromBlue alpha:&fromAlpha];

CGFloat toRed, toGreen, toBlue, toAlpha;
[toColor getRed:&toRed green:&toGreen blue:&toBlue alpha:&toAlpha];

//calculate the actual RGBA values of the fade colour
CGFloat red = (toRed - fromRed) * percentage + fromRed;
CGFloat green = (toGreen - fromGreen) * percentage + fromGreen;
CGFloat blue = (toBlue - fromBlue) * percentage + fromBlue;
CGFloat alpha = (toAlpha - fromAlpha) * percentage + fromAlpha;

// return the fade colour
return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];

}

相关文章

  • 代码片段合集

    UIScrollView scroll change background color } }

  • 片段合集

    片段一 再次来到这片林海,史也仿佛得到了救赎。二十一年,这片林海仿佛幻化成那虚无的十字架,重重把自己钉在上面,在悔...

  • Xcode代码块

    代码片段 Xcode的代码片段(Code Snippets)创建自定义的代码片段,当你重用这些代码片段时,会给你带...

  • vscode 代码片段设置

    文件-首选项-用户片段 选择新建代码片段 打印代码片段

  • 代码片段&编程小技巧

    代码片段大全代码片段,代码分享,PHP代码分享,Java代码分享,Ruby代码分享,Python代码分享,HTML...

  • 代码片段

    消除table中的th除去了所有border,margin,padding之后还是会有间隙的问题 移动端必须加的代...

  • 代码片段

    简介: 关于代码片段,网上已经有很多资料了,这里主要介绍下结合zyApi如何快速的写出请求模版。 实现: 上面三份...

  • 代码片段

    for循环和迭代器 在判断一个数组中是否包含某个值的时候,开发者经常这样做: 推荐使用for循环遍历的形式或者使用...

  • 代码片段

    单例模式 获取Keystore 证书指纹

  • 代码片段

    目录: 找到手机上所有安装的浏览器信息 对TextView更改字体 ListView 使用BaseAdapter的...

网友评论

      本文标题:代码片段合集

      本文链接:https://www.haomeiwen.com/subject/ueikoxtx.html