iOS - Smooth Color Change Transition/Animation

前端 未结 3 696
不知归路
不知归路 2021-02-07 01:47

I want to have a smooth color transition that goes across the entire spectrum (i.e. red, blue, green, yellow, orange, etc.)

Also want to be able to have smooth transitio

3条回答
  •  旧巷少年郎
    2021-02-07 02:24

    One very simple way to accomplish this would be to use a UIView animation block.

    [UIView animateWithDuration:1.0 animations:^{
        view.backgroundColor = [UIColor redColor];
    }];
    

    This will interpolate between whatever view's previous background color was, and red over the course of 1 second.

    Swift:

    UIView.animate(withDuration: 1.0) { 
        view.backgroundColor = .red
    }
    

提交回复
热议问题