gpt4 book ai didi

ios - CAGradientLayer 显示完全半透明

转载 作者:行者123 更新时间:2023-12-01 17:31:48 30 4
gpt4 key购买 nike

我正在尝试创建两个渐变层,一个位于 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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com