// ViewController.m函數
// IOS動畫0817動畫
//atom
// Created by 張豔鋒 on 15/8/17.url
// Copyright (c) 2015年 張豔鋒. All rights reserved.orm
//blog
#import "ViewController.h"ip
@interface ViewController ()ci
@property (weak, nonatomic) IBOutlet UIImageView *imageview;animation
- (IBAction)doAnimationButton:(id)sender;it
- (IBAction)doLeftButton:(id)sender;
- (IBAction)doRightButton:(id)sender;
- (IBAction)doUpButton:(id)sender;
- (IBAction)doDownButton:(id)sender;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)doAnimationButton:(id)sender {
/********隱式動畫********/
/*
[UIView beginAnimations:nil context:NULL];//動畫開始標誌
//定義一個仿射變換
CGAffineTransform moveTrans=CGAffineTransformMakeTranslation(300, 600);
// CGAffineTransformMakeTranslation//更改位置的函數
// CGAffineTransformMakeRotation//k控制旋轉
//CGAffineTransformMakeScale//控制縮放
[_imageview.layer setAffineTransform:moveTrans];
[UIView commitAnimations];//提交動畫
*/
/********顯式動畫********/
//定義顯示動畫的時候,咱們沒必要定義CALayer的變化,也沒必要執行它,而是經過CABasicAnimation逐個定義動畫,其中每一個動畫都含有各自的屬性,而後經過addAnimation:方法添加到圖層中
/*
CABasicAnimation *basic=[CABasicAnimation animationWithKeyPath:@"opacity"];//opacity表示透明度
basic.duration=6.0;//6秒內透明度變爲零
basic.fromValue=[NSNumber numberWithFloat:0.2];//初始透明度
basic.toValue=[NSNumber numberWithFloat:1.0];//最終透明度
basic.cumulative=YES;//設置透明度遞增
[_imageview.layer addAnimation:basic forKey:@"animateOpacity"];
CGAffineTransform moveTrans1=CGAffineTransformMakeTranslation(300, 600);
CABasicAnimation *basic_move=[CABasicAnimation animationWithKeyPath:@"transform"];//準備函數(爲平移作準備)
basic_move.duration=6.0;
//CATransform3DMakeAffineTransform仿射變換爲3D效果(仿射不能直接應用於顯式動畫)
basic_move.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeAffineTransform(moveTrans1)];
[_imageview.layer addAnimation:basic_move forKey:@"animateTransform2"];
*/
/********關鍵幀動畫********/
/*
CAKeyframeAnimation *keyAnimation=[CAKeyframeAnimation animationWithKeyPath:@"opacity"];//透明度
keyAnimation.duration=6.0;//動畫時間
keyAnimation.values=[NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0],[NSNumber numberWithFloat:0.6],[NSNumber numberWithFloat:1.0], nil];//
keyAnimation.keyTimes=[NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0],[NSNumber numberWithFloat:0.3],[NSNumber numberWithFloat:1.0], nil];
[_imageview.layer addAnimation:keyAnimation forKey:@"animateOpcaty"];
CGAffineTransform moveTrans2=CGAffineTransformMakeTranslation(300, 600);
CABasicAnimation *basic_move2=[CABasicAnimation animationWithKeyPath:@"transform"];
basic_move2.duration=6.0;
basic_move2.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeAffineTransform(moveTrans2)];
[_imageview.layer addAnimation:basic_move2 forKey:@"animateTransform2"];
*/
}
//系統自帶反轉動畫(上下左右)
- (IBAction)doLeftButton:(id)sender {
//三次向左不返回
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.5f];//動畫時間
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];//設置動畫曲線方式(動畫的整體變化時間曲線,包含開始慢後來快,開始快後來慢,均勻曲線)
[UIView setAnimationRepeatAutoreverses:NO];//設置動畫是否作一次反向操做
[UIView setAnimationRepeatCount:3];//執行次數
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];//
[UIView commitAnimations];
}
- (IBAction)doRightButton:(id)sender {
//三次向右有返回
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationRepeatAutoreverses:YES];
[UIView setAnimationRepeatCount:3];//執行次數
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[UIView commitAnimations];
}
- (IBAction)doUpButton:(id)sender {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationRepeatAutoreverses:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[UIView commitAnimations];
}
- (IBAction)doDownButton:(id)sender {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationRepeatAutoreverses:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
[UIView commitAnimations];
}