如何在iOS中产生这种效果,模糊效果正在增加学习者对低端的影响

时间:2014-04-24 07:32:22

标签: ios ios7

我正在搜索这个,但我没有找到解决我问题的确切方法,所有制作模糊效果的答案都显示了在整个画面上产生模糊效果,但我希望模糊效果看起来像下面的图像

enter image description here

在图像中,模糊效果位于底部,它越来越向下侧倾斜

任何人都可以知道如何做到这一点,任何想法或示例代码... :)

1 个答案:

答案 0 :(得分:3)

使用CAGradientLayer

UIColor *theColor = [[UIColor alloc] initWithRed:146.0/255.0 green:146.0/255.0 blue:146.0/255.0 alpha:1];

CAGradientLayer *gradientLayer = [CAGradientLayer layer];

CGRect gradientLayerFrame = theView.frame;
gradientLayerFrame.origin.x = 0;
gradientLayerFrame.origin.y = 0;
gradientLayer.frame = gradientLayerFrame;

//build the colors array for the gradient
NSArray *colors = [NSArray arrayWithObjects:
                   (id)[theColor CGColor],
                   (id)[[theColor colorWithAlphaComponent:0.9f] CGColor],
                   (id)[[theColor colorWithAlphaComponent:0.6f] CGColor],
                   (id)[[theColor colorWithAlphaComponent:0.4f] CGColor],
                   (id)[[theColor colorWithAlphaComponent:0.3f] CGColor],
                   (id)[[theColor colorWithAlphaComponent:0.1f] CGColor],
                   (id)[[UIColor clearColor] CGColor],
                   nil];

gradientLayer.colors = colors;

[yourView.layer insertSublayer:gradientLayer atIndex:0];

此代码的快速版本为here