zoukankan      html  css  js  c++  java
  • CABasicAnimation 核心动画

    //

    //  ZBMainViewController.m

    //  TestProject

    //

    //  Created by 张先森 on 14/12/5.

    //  Copyright (c) 2014年 zhibin. All rights reserved.

    //

    #import "ZBMainViewController.h"

    @interface ZBMainViewController ()

    @property(nonatomic,strong)CALayer *mylayer;

    @end

    @implementation ZBMainViewController

     bool isopen=NO;

    - (void)viewDidLoad {

        [super viewDidLoad];

        [self InitControls];

    }

    -(void)InitControls{

        CALayer *mylayer=[CALayer layer];

        mylayer.bounds=CGRectMake(0, 0, 100, 100);

        mylayer.backgroundColor=[UIColor yellowColor].CGColor;

        mylayer.position=CGPointMake(100, 100);

        mylayer.anchorPoint=CGPointMake(0, 0);

        mylayer.cornerRadius=10;

        [self.view.layer addSublayer:mylayer];

        self.mylayer=mylayer;

        

    }

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

        if (!isopen) {

            

      

        CABasicAnimation *anim=[CABasicAnimation animation];

        anim.keyPath=@"position";

        anim.duration=10;

        anim.fromValue=[NSValue valueWithCGPoint:CGPointMake(100, 100)];

        anim.toValue=[NSValue valueWithCGPoint:CGPointMake(150, 300)];

        anim.removedOnCompletion=NO;

        anim.fillMode=kCAFillModeForwards;

        [self.mylayer addAnimation:anim forKey:@"move"];

            

            isopen=true;

        }else{

            

             isopen=false;

            [self.mylayer removeAnimationForKey:@"move"];

        

        

        }

    }

    @end

  • 相关阅读:
    Sql Sugar
    GoLang 环境部署
    Typora 自动添加序号
    C# 操作 Oracle批量执行Insert Blob
    C# 生成读取二维码
    Asp.net core 使用Serilog记录日志
    Asp.net Core 将日志输出到文件
    云原生领域的一些技术展望
    C# BeginInvoke用法记录
    C# 委托及线程
  • 原文地址:https://www.cnblogs.com/zhibin/p/4152244.html
Copyright © 2011-2022 走看看