本文介绍了CAGradientLayer和scrollViewTexturedBackgroundColor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用CAGradientLayer相对于背景纹理视图淡化前景控件。
因此,总的来说,我有一个bg颜色为scrollViewTexturedBackgroundColor的视图。我在此之上有一个视图,我想将其内容在边框处淡化为背景视图的颜色。

I'm trying to use CAGradientLayer to fade foreground controls against the background textured view.So in a nutshell, I have a view with the bg color as scrollViewTexturedBackgroundColor. I have a view on top of that, whose contents I'd like to fade at the border into the background view's color.

CAGradientLayer* gradient = [CAGradientLayer layer];
gradient.frame = self->scrollableCanvas.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor scrollViewTexturedBackgroundColor] CGColor], (id)[[UIColor scrollViewTexturedBackgroundColor] CGColor], nil];
[gradient setStartPoint:CGPointMake(0.90, 1)];
[gradient setEndPoint:CGPointMake(1, 1)];    
[[self->scrollableCanvas layer] addSublayer:gradient];
[[self->scrollableCanvas layer] setMasksToBounds:YES];

不幸的是,CAGradientLayer似乎不支持UIColors作为图案图像。

Unfortunately, CAGradientLayer doesn't seem to support UIColors as pattern images.

有什么想法可以为子视图实现简单的边框淡入淡出效果吗?

any ideas how I can achieve a simple border fade effect for the subview?

谢谢

推荐答案

您可以使用一些技巧:

//create normal UIImageView
UIImageView* iv = [[[UIImageView alloc] initWithImage: [UIImage imageNamed :@"bg_png.png"]] autorelease];
[superview addSubview: iv];

//draw gradient on top
UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = view.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithWhite: 1.0 alpha: 0.0] CGColor], (id)[[UIColor colorWithWhite: 1.0 alpha: 1.0] CGColor], nil];
[view.layer insertSublayer:gradient atIndex:0];
[superview addSubview: view];

这篇关于CAGradientLayer和scrollViewTexturedBackgroundColor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 17:32