ios - CAGradientLayer 显示完全半透明

标签 ios objective-c cocoa-touch calayer

我正在尝试创建两个渐变层,一个位于 ScrollView 的每一侧,以显示有要滚动到的内容。

左侧的效果很好,但右侧的显示完全透明。我错过了什么?

Xib

Reveal

CAGradientLayer *l = [CAGradientLayer layer];
l.frame = self.leftBlur.frame;
l.colors = [NSArray arrayWithObjects:(id)[UIColor whiteColor].CGColor, (id)[UIColor clearColor].CGColor, nil];
l.startPoint = CGPointMake(0.0f, 0.5f);
l.endPoint = CGPointMake(1.0f, 0.5f);
self.leftBlur.layer.mask = l;

self.leftBlur.hidden = YES;

CAGradientLayer *r = [CAGradientLayer layer];
r.frame = self.rightBlur.frame;
r.colors = [NSArray arrayWithObjects:(id)[UIColor clearColor].CGColor, (id)[UIColor whiteColor].CGColor, nil];
r.startPoint = CGPointMake(0.0f, 0.5f);
r.endPoint = CGPointMake(1.0f, 0.5f);
self.rightBlur.layer.mask = r;

调试输出:
(lldb) po r
<CAGradientLayer:0x170ba6d0; position = CGPoint (305 62.5); bounds = CGRect (0 0; 30 125); allowsGroupOpacity = YES; endPoint = CGPoint (1 0.5); startPoint = CGPoint (0 0.5); colors = (
    "<CGColor 0x15e590e0> [<CGColorSpace 0x15e34b50> (kCGColorSpaceDeviceGray)] ( 1 1 )",
    "<CGColor 0x17012ed0> [<CGColorSpace 0x15d15310> (kCGColorSpaceDeviceRGB)] ( 1 0 0 1 )"
)>
(lldb) po self.rightBlur
<UIImageView: 0x171377d0; frame = (290 0; 30 125); autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x17137860>>
(lldb) po l
<CAGradientLayer:0x170b9f00; position = CGPoint (15 62.5); bounds = CGRect (0 0; 30 125); allowsGroupOpacity = YES; endPoint = CGPoint (1 0.5); startPoint = CGPoint (0 0.5); colors = (
    "<CGColor 0x15e590e0> [<CGColorSpace 0x15e34b50> (kCGColorSpaceDeviceGray)] ( 1 1 )",
    "<CGColor 0x15d39320> [<CGColorSpace 0x15e34b50> (kCGColorSpaceDeviceGray)] ( 0 0 )"
)>
(lldb) po self.leftBlur
<UIImageView: 0x17136fc0; frame = (0 0; 30 125); hidden = YES; autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x17137050>>

最佳答案

问题很可能是由于颜色来自不同的颜色空间。当你这样做时请注意 po r ,颜色不在同一个颜色空间中 - 一种来自 RGB,另一种来自灰色。

我建议不要使用 [UIColor clearColor] , 你使用 [UIColor colorWithWhite:1.0 alpha:0.0] .与 [UIColor whiteColor] 一起使用因为另一种颜色将导致两种颜色处于相同的颜色空间中。

编辑:实际上问题可能是 frame "diederikh"指出的问题。

关于ios - CAGradientLayer 显示完全半透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19074582/

相关文章:

iphone - Facebook 不允许使用 ios 应用程序的帐户

ios - ViewForHeaderInSection 代码仅适用于 header 出列

ios - 在 Swift 中获取坐标 (x,y) 处的 UILabel 值

iphone - 在iOS上使用后台任务进行UI更新

ios - 具有自定义背景颜色的自定义 UIPickerView

objective-c - 将 kal 日历实现到选项卡栏应用程序中

ios - 在单个 UIVIewController 中垂直放置两个全屏 UIView?

iphone - 如何在不使用TexturePacker的情况下在Cocos2D中添加动画图像?

objective-c - 数据序列化

iphone - 在 Objective C 中序列化对象