我正在尝试创建两个渐变层,一个位于滚动视图的每一侧,以显示有要滚动到的内容。
左侧的效果很好,但右侧的显示完全透明。我错过了什么?
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>>