iOS Obj-c渐变背景过渡

iOS Obj-c gradient background transition

我想逐渐改变背景渐变

gradient.colors = [NSArray arrayWithObjects:(id)[UIColor.blackColor CGColor],(id)[UIColor.blueColor CGColor], nil];

gradient.colors = [NSArray arrayWithObjects:(id)[UIColor.grayColor CGColor],(id)[UIColor.cyanColor CGColor], nil];

[编辑] 我当前的代码是:

                gradient.colors = [NSArray arrayWithObjects:(id)[UIColor.blackColor CGColor],(id)[UIColor.blueColor CGColor], nil];
                NSArray *fromColors = gradient.colors;
                NSArray *toColors =[NSArray arrayWithObjects:(id)[UIColor.grayColor CGColor],(id)[UIColor.cyanColor CGColor], nil];
                CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath: @"colors"];

                animation.fromValue = fromColors;
                animation.toValue = toColors;
                animation.duration = 3.00;
                animation.removedOnCompletion = false;
                animation.autoreverses = NO;
                animation.fillMode = kCAFillModeForwards;
                animation.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionLinear];
                if (![gradient.animationKeys containsObject:@"colors"]) {
                    [gradient addAnimation:animation forKey:@"colors"];
                }
                [self.background.layer addSublayer:gradient];

但它什么也没做。有人可以帮我吗?

我认为CABasicAnimation.keypath.But不支持“颜色”如何满足要求,我仍然想不出answer.