美文网首页iOS绘图与动画
[动画学习]CATransition背景色动画设置

[动画学习]CATransition背景色动画设置

作者: flyWhite | 来源:发表于2019-01-28 16:23 被阅读3次
    CATransition 是CAAnimation的子类,用了控制过渡动画。有一个type和subtype来标识变换效果。
    
    CATransition1
    CATransition2
    -(void)Animation{
        self.colorlayer = [CALayer layer];
        self.colorlayer.frame = CGRectMake(50.0f, 50.0f, 100.0f, 100.0f);
        self.colorlayer.backgroundColor = [UIColor blueColor].CGColor;
        //add a custom action
        CATransition *transition = [CATransition animation];
        //样式
        transition.type = kCATransitionPush;
        //方向
        transition.subtype = kCATransitionFromTop;
        self.colorlayer.actions = @{@"backgroundColor": transition};
        
        
        //add it to our view
        
        [self.layerView.layer addSublayer:self.colorlayer];
    }
    - (IBAction)actionBtnclick:(id)sender {
        
        [CATransaction begin];
        //调整动画时长 隐式动画默认时长0.25
        [CATransaction setAnimationDuration:0.5];
        [CATransaction setCompletionBlock:^{
            NSLog(@"动画结束回掉");
        }];
        CGFloat red = arc4random() / (CGFloat)INT_MAX;
        CGFloat green = arc4random() / (CGFloat)INT_MAX;
        CGFloat blue = arc4random() / (CGFloat)INT_MAX;
        self.colorlayer.backgroundColor = [UIColor colorWithRed:red green:green blue:blue alpha:1.0].CGColor;
        [CATransaction commit];
    }
    

    相关文章

      网友评论

        本文标题:[动画学习]CATransition背景色动画设置

        本文链接:https://www.haomeiwen.com/subject/jkiajqtx.html