• CATransform3D的m34值动画


    CATransform3D的m34值动画

    效果

    源码

    https://github.com/YouXianMing/Animations

    //
    //  CATransform3DM34Controller.m
    //  Animations
    //
    //  Created by YouXianMing on 16/1/9.
    //  Copyright © 2016年 YouXianMing. All rights reserved.
    //
    
    #import "CATransform3DM34Controller.h"
    #import "GCD.h"
    #import "Math.h"
    
    @interface CATransform3DM34Controller ()
    
    @property (nonatomic, strong) CALayer   *layer;
    @property (nonatomic, strong) GCDTimer  *timer;
    @property (nonatomic)         BOOL       transformState;
    
    @end
    
    @implementation CATransform3DM34Controller
    
    - (void)setup {
    
        [super setup];
        
        [self initLayer];
        
        [self timerEvent];
    }
    
    - (void)initLayer {
    
        // Init layer.
        UIImage *image         = [UIImage imageNamed:@"1"];
        self.layer             = [CALayer layer];
        self.layer.frame       = CGRectMake(0, 0, image.size.width / 2.f, image.size.height / 2.f);
        self.layer.position    = self.view.center;
        self.layer.borderWidth = 4.f;
        self.layer.borderColor = [UIColor blackColor].CGColor;
        self.layer.contents    = (__bridge id)image.CGImage;
        [self.view.layer addSublayer:self.layer];
    }
    
    - (void)timerEvent {
    
        // Timer event.
        self.timer = [[GCDTimer alloc] initInQueue:[GCDQueue mainQueue]];
        [self.timer event:^{
            
            if (self.transformState == NO) {
                
                self.transformState = YES;
                [self transformStateEvent];
                
            } else {
                
                self.transformState = NO;
                [self normalStateEvent];
            }
            
        } timeIntervalWithSecs:3.f delaySecs:3.f];
        [self.timer start];
    }
    
    - (void)transformStateEvent {
    
        // 初始化3D变换,获取默认值
        CATransform3D perspectiveTransform = CATransform3DIdentity;
        
        // 透视
        perspectiveTransform.m34 = -1.0/500.0;
        
        // 位移
        perspectiveTransform = CATransform3DTranslate(perspectiveTransform, 30, -35, 0);
        
        // 空间旋转
        perspectiveTransform = CATransform3DRotate(perspectiveTransform, [Math radianFromDegree:30], 0.75, 1, -0.5);
        
        // 缩放变换
        perspectiveTransform = CATransform3DScale(perspectiveTransform, 0.75, 0.75, 0.75);
        
        self.layer.transform = perspectiveTransform;
        self.layer.speed     = 0.5;
    }
    
    - (void)normalStateEvent {
    
        // 初始化3D变换,获取默认值
        CATransform3D perspectiveTransform = CATransform3DIdentity;
        
        self.layer.transform = perspectiveTransform;
        self.layer.speed     = 0.5;
    }
    
    @end

    细节

  • 相关阅读:
    Linux面试题(后续会不断更新)
    01 . Shell详细入门介绍及简单应用
    06 . Prometheus监控Redis并配置Grafana
    Django实现图片上传并前端页面显示
    03 . 二进制部署kubernetes1.18.4
    Docker部署Python项目
    02 . Kubeadm部署Kubernetes及简单应用
    01 . 容器编排简介及Kubernetes核心概念
    05 . Prometheus监控Nginx
    GoAccess分析Web日志
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/5117424.html
Copyright © 2020-2023  润新知