IOS动画 旋转两圈

//
//  ViewController.m
//  KeyFrameAnimation
//
//  Created by vincent_guo on 13-9-6.
//  Copyright (c) 2013年 vincent_guo. All rights reserved.
//
 
#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>
 
@interface ViewController (){
     UIImageView *_imageView;
}
 
@end
 
@implementation ViewController
 
- ( void )viewDidLoad
{
     [super viewDidLoad];
     // Do any additional setup after loading the view, typically from a nib.
     _imageView = [[UIImageView alloc] init];
     _imageView.bounds = CGRectMake(0, 0, 80, 80);
     _imageView.center = CGPointMake(160, 50);
     _imageView.image = [UIImage imageNamed:@ "clock" ];
     [self.view addSubview:_imageView];
     [_imageView release];
}
 
-( void )click:(id)sender{
     [self turnTwoRound2];
}
 
#pragma mark 使用CABasicAnimation让View向左转两圈,要向右转两圈,把-M_PI负号去掉就可以了
-( void )turnTwoRound1 {
     CABasicAnimation* rotationAnimation;
     rotationAnimation = [CABasicAnimation animationWithKeyPath:@ "transform.rotation.z" ];
     rotationAnimation.toValue = [NSNumber numberWithFloat: -M_PI * 2.0 ];
     rotationAnimation.duration = 0.5;
     rotationAnimation.repeatCount = 2; //动画执行两次
     [_imageView.layer addAnimation:rotationAnimation forKey:@ "rotationAnimation" ];
}
 
 
#pragma mark 使用CAKeyframeAnimation让View向左转两圈,要向右转两圈,把-M_PI负号去掉就可以了
-( void )turnTwoRound2{
     CAKeyframeAnimation *rotateAnimation = [CAKeyframeAnimation animationWithKeyPath:@ "transform.rotation.z" ];
     rotateAnimation.duration = 0.5;
     //先从原始位置向左转180度,再向左转180度是-M_PI*4,不是-M_PI*2哦,自己好好理解下)
     rotateAnimation.values = [NSArray arrayWithObjects:
                               [NSNumber numberWithFloat:0.0f],
                               [NSNumber numberWithFloat:-M_PI * 2],
                               [NSNumber numberWithFloat:-M_PI * 4], nil];
     [_imageView.layer addAnimation:rotateAnimation forKey:@ "rotationAnimation" ];
}
 
@end

转自:http://www.cnblogs.com/vincent-guo/p/3305428.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值