在我的应用程序中,我有一个视图,我希望它在左侧和右侧有一个小的透明渐变。我可以很容易地创建左或右渐变,但我不知道如何组合它们:
CAGradientLayer *rightLayer = [CAGradientLayer layer];
rightLayer.frame = self.bounds;
rightLayer.colors = [NSArray arrayWithObjects:(id)[UIColor whiteColor].CGColor, (id)[UIColor clearColor].CGColor, nil];
rightLayer.startPoint = CGPointMake(0.8f, 1.0f);
rightLayer.endPoint = CGPointMake(1.0f, 1.0f);
CAGradientLayer *leftLayer = [CAGradientLayer layer];
leftLayer.frame = self.bounds;
leftLayer.colors = [NSArray arrayWithObjects:(id)[UIColor clearColor].CGColor,(id)[UIColor whiteColor].CGColor, nil];
leftLayer.startPoint = CGPointMake(0.0f, 1.0f);
leftLayer.endPoint = CGPointMake(0.2f, 1.0f);
self.layer.mask = leftLayer;
如您所见,问题是我必须只为蒙版分配 1 层,并且我希望它有 2 层。如何合并 leftLayer 和 rightLayer?或者我如何将这两个图层都添加到掩码中?
非常感谢您的回答!