zoukankan      html  css  js  c++  java
  • iOS UI 21 动画



    //

    //  RootViewController.m

    //  UI - 21 动画

    //

    //  Created by dllo on 15/12/8.

    //  Copyright (c) 2015 dllo. All rights reserved.

    //


    #import "RootViewController.h"


    @interface RootViewController ()

    @property (nonatomic, retain)UIImageView *imagev;


    @end


    @implementation RootViewController


    - (void)viewDidLoad {

        [super viewDidLoad];

        self.view.backgroundColor = [UIColor whiteColor];

        

        self.imagev = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 50, 50)];

        self.imagev.image =[UIImage imageNamed:@"Stars.png"];

        [self.view addSubview:self.imagev];

        [self.imagev release];

        

        

        UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];

        //layer

        //阴影颜色

        button.layer.shadowColor = [[UIColor blackColor]CGColor];

        //阴影偏移

        button.layer.shadowOffset = CGSizeMake(2, 3);

        //阴影透明度

        button.layer.shadowOpacity = 0.5;

        //阴影透明度

        button.layer.shadowRadius = 0.5;

        //设置圆角 宽和高一样, 圆角设置为宽的一半

    //    button.layer.cornerRadius = 25;

        

    //    button.layer.masksToBounds = YES;

        //描边颜色

        button.layer.borderColor = [[UIColor yellowColor] CGColor];

        //描边宽度

        button.layer.borderWidth = 5;

        

        

        button.frame = CGRectMake(100, 300, 50, 50);

        button.backgroundColor = [UIColor redColor];

        [button addTarget:self action:@selector(buttonAct:) forControlEvents:UIControlEventTouchUpInside];

        [self.view addSubview:button];

        

        

        

        

        

        

        

        

        

        

        // Do any additional setup after loading the view.

    }

    - (void)buttonAct:(UIButton *)sender

    {

    //    [UIView animateWithDuration:1.f animations:^{

    //        //延时

    //        [UIView setAnimationDelay:1];

    //        //速度曲线

    //        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

    //        //动画反转

    //        [UIView  setAnimationRepeatAutoreverses:YES];

    //        //重复次数

    //        [UIView setAnimationRepeatCount:3.0];

    //        

    //        

    //        self.imagev.frame = CGRectMake(300, 500, 100, 100);

    //    }];

        

        

    //    [UIView animateWithDuration:1.f animations:^{

    //        

    //        self.imagev.frame = CGRectMake(300, 500, 100, 100);

    //

    //    } completion:^(BOOL finished) {

    //        //动画完成后可以加一些处理

    //         self.imagev.frame = CGRectMake(0, 0, 100, 100);

    //    }];

        

    //    [UIView animateWithDuration:1.0f delay:1.0 options:    UIViewAnimationOptionCurveEaseInOut animations:^{

    //        

    //        self.imagev.frame = CGRectMake(300, 500, 100, 100);

    //    } completion:^(BOOL finished) {

    //        

    //        self.imagev.frame = CGRectMake(0, 0, 100, 100);

    //    }];

        

    //    UIView * view1 = [[[UIView alloc]initWithFrame:CGRectMake(0, 300, 50, 50)]autorelease];

    //    view1.backgroundColor = [UIColor redColor];

    //    [self.view addSubview:view1];

    //    

    //    [UIView transitionFromView:view1 toView:sender duration:1.0 options:UIViewAnimationOptionCurveEaseOut completion:^(BOOL finished) {

    //        

    //        

    //    }];

        

        //基础动画

        CABasicAnimation *basicA = [CABasicAnimation animationWithKeyPath:@"transform.scale"];

    //    //起始值

        basicA.fromValue = @(1);

        basicA.toValue = @(3);

        basicA.duration = 3.f;

        basicA.autoreverses = YES;

        basicA.repeatCount = NSIntegerMax;

    //

    //    [self.imagev.layer addAnimation:basicA forKey:@"aaa"];

        

        CABasicAnimation *basicA1 = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];

        basicA1.fromValue = @(0);

        basicA1.toValue = @(2 * M_PI);

        basicA1.duration = 3.f;

    //    basicA1.autoreverses = YES;

        basicA1.repeatCount = NSIntegerMax;

    //  [self.imagev.layer addAnimation:basicA1 forKey:@"bbb"];

        

        CAAnimationGroup *groupA = [CAAnimationGroup animation];

        groupA.animations = @[basicA , basicA1];

        //一部分参数会覆盖原有参数

         groupA.duration = 3.f;

        groupA.repeatCount = NSIntegerMax;

         groupA.autoreverses = YES;

        [self.imagev.layer addAnimation:groupA forKey:@"ccc"];

        

        // 帧动画

        CAKeyframeAnimation *keyframeA = [CAKeyframeAnimation animationWithKeyPath:@"position"];

        //创建可变路径

        CGMutablePathRef path = CGPathCreateMutable();

        //设置轨迹

        CGPathMoveToPoint(path, NULL, 50, 50);

        CGPathAddLineToPoint(path, NULL, 100, 100);

        CGPathAddLineToPoint(path, NULL, 250, 100);

        CGPathAddLineToPoint(path, NULL, 250, 250);

        CGPathAddLineToPoint(path, NULL, 100, 100);

        //曲线

        //需要设置3个坐标点

        // (cp1x, cp1y),(cp2x, cp2y)- 会尽量靠近这两个点但不会穿过

        //(x, y) - 目的点

        

        CGPathAddCurveToPoint(path, NULL, 50, 50, 300, 300, 300, 500);

        keyframeA.duration = 3;

        keyframeA.path = path;

        

    //     [self.imagev.layer addAnimation:keyframeA forKey:@"ddd"];

       

        CATransition *tran = [CATransition animation];

        tran.type = @"cube";

        //做方向

        tran.duration = 0.2f;

        tran.subtype =kCAGravityTopLeft;

        tran.repeatCount = NSIntegerMax;

    //    [sender.layer addAnimation:tran forKey:@"eee"];

        

    }

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }


    /*

    #pragma mark - Navigation


    // In a storyboard-based application, you will often want to do a little preparation before navigation

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

        // Get the new view controller using [segue destinationViewController].

        // Pass the selected object to the new view controller.

    }

    */


    @end


  • 相关阅读:
    BroadcastReceiver总结
    一二三(The Seventh Hunan Collegiate Programming Contest)
    使用 JQueryMobile 点击超链接提示“error loading page” 错误
    盒子游戏(The Seventh Hunan Collegiate Programming Contest)
    遗留系统升级改造方案思路
    根据外接鼠标控制笔记本触摸板禁用或启用
    设计模式之策略模式
    android4.3环境搭建
    清晰明亮的白色lua协程(coroutine)
    基于JUnit和Ant测试程序正在运行使用Kieker(AspectJ)监测方法
  • 原文地址:https://www.cnblogs.com/yuhaojishuboke/p/5043067.html
Copyright © 2011-2022 走看看