设为首页 加入收藏

TOP

CABasicAnimation学习Demo 包括了一些常用的动画效果(一)
2015-07-24 05:57:55 来源: 作者: 【 】 浏览:13
Tags:CABasicAnimation 学习 Demo 包括 一些 常用 动画 效果

个人写的一些例子:

//
//  ViewController.m
//  CABasicAnimationDemo
//
//  Created by haotian on 14-6-13.
//  Copyright (c) 2014年 Baseus. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize ViewTest;
- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    //self.ViewTest.backgroundColor = [UIColor redColor];
    //组合动画调用
    //[self startAnimation2];
    
    //永久闪烁动画
    //[self opacityForever_Animation:0.3];
    
    ////有闪烁次数的动画
    //[self opacityTimes_Animation:10 durTimes:0.3];
    
    //画一条线    路径
    [self drawACurvedLine];
    
    //路径动画
    //[self animateCicleAlongPath];
    
}

-(void)startAnimation
{
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
    animation.fromValue = [NSValue valueWithCGPoint:CGPointMake(50, 50)];
    animation.toValue = [NSValue valueWithCGPoint:CGPointMake(300, 300)];
    animation.duration = 3.0f;
    animation.repeatCount = 1;
    //animation.removedOnCompletion = NO; //完成后是否回到原来状态,如果为NO 就是停留在动画结束时的状态
    //animation.fillMode = kCAFillModeRemoved;//动画完成后返回到原来状态
    //animation.fillMode = kCAFillModeBackwards;
    animation.fillMode = kCAFillModeForwards;//当动画完成时,保留在动画结束的状态
    
    [self.ViewTest.layer addAnimation:animation forKey:nil];
}

-(void)startAnimation1
{
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];
    animation.fromValue = [NSNumber numberWithFloat:0.0f];
    animation.toValue   = [NSNumber numberWithFloat:10.0f];
    //animation.duration = 0.5f;
    //animation.fillMode = kCAFillModeForwards;
    //animation.removedOnCompletion = NO;
    //animation.repeatCount = 2;
    //[self.ViewTest.layer addAnimation:animation forKey:nil];
    
    CABasicAnimation *animation1 = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
    animation.fromValue = [NSNumber numberWithFloat:0.0f];
    animation.toValue   = [NSNumber numberWithFloat:10.0f];
    //animation.duration = 0.5f;
    //animation.fillMode = kCAFillModeForwards;
    //animation.removedOnCompletion = NO;
    //animation.repeatCount = 2;
    //[self.ViewTest.layer addAnimation:animation1 forKey:nil];

    CAAnimationGroup *groupAnimation = [CAAnimationGroup animation];
    groupAnimation.duration = 2.0f;
    groupAnimation.autoreverses  = YES;
    groupAnimation.repeatCount = 5;
    [groupAnimation setAnimations:[NSArray arrayWithObjects:animation,animation1, nil]];
    
    [self.ViewTest.layer addAnimation:groupAnimation forKey:nil];
}

//组合动画
-(void)startAnimation2
{
    //界限
    CABasicAnimation *boundsAnimation = [CABasicAnimation animationWithKeyPath:@"bounds"];
    boundsAnimation.fromValue = [NSValue valueWithCGRect: self.ViewTest.bounds];
    boundsAnimation.toValue = [NSValue valueWithCGRect:CGRectZero];
    //透明度变化
    CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
    opacityAnimation.fromValue = [NSNumber numberWithFloat:1.0];
    opacityAnimation.toValue = [NSNumber numberWithFloat:0.5];
    
    //位置移动
    CABasicAnimation *animation  = [CABasicAnimation animationWithKeyPath:@"position"];
    animation.fromValue =  [NSValue valueWithCGPoint: self.ViewTest.layer.position];
    CGPoint toPoint = self.ViewTest.layer.position;
    toPoint.x += 180;
    animation.toValue = [NS
首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C++11 新特性之 变长参数模板 下一篇ajax――XMLHttpRequest

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: