设置动画代理、开始结束响应函数、关键帧动画

//

#import "ViewController.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIView *greenView;

@end

@implementation ViewController

- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view, typically from a nib.}


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


// [UIView beginAnimations:@"1"/*animationID*/ context:nil];


//设置代理

// [UIView setAnimationDelegate:self];

//开始的响应函数

//[UIView setAnimationWillStartSelector:@selector(animationWillStart:context:)];

//结束时响应函数

//  [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];


//set函数放前面

// [UIView setAnimationRepeatCount:2];

//  [UIView setAnimationRepeatAutoreverses:YES];

// [UIView setAnimationDuration:3];

//  [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];//出入速度

// self.greenView.transform = CGAffineTransformRotate(self.greenView.transform, M_1_PI);

//transition动画(翻转)过渡效果

//  [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft /*从左往右反转*/forView:self.greenView cache:NO/YES];

// [UIView commitAnimations];


//block动画

/* [UIView animateWithDuration:<#(NSTimeInterval)#> animations:<#^(void)animations#>];

[UIView animateWithDuration:<#(NSTimeInterval)#> animations:<#^(void)animations#> completion:<#^(BOOL finished)completion#>];

[UIView animateWithDuration:<#(NSTimeInterval)#> delay:<#(NSTimeInterval)#> options: 动画效果 animations:<#^(void)animations#> completion:<#^(BOOL finished)completion#>]; */


弹簧震动动画

/* [UIView animateWithDuration:2.0 delay:0.0 usingSpringWithDamping:0.1

//0-1

initialSpringVelocity:5.0 options:UIViewAnimationOptionTransitionCurlUp animations:^{

self.greenView.transform = CGAffineTransformTranslate(self.greenView.transform, 25, 30);          }completion:^(BOOL finished){

}];*/

self.greenView.frame = CGRectMake(0, 0, 100, 50);


关键帧动画

//创建

[UIView animateKeyframesWithDuration:2.0 delay:0 options:UIViewKeyframeAnimationOptionCalculationModeLinear animations:^{

//添加

[UIView addKeyframeWithRelativeStartTime:0 relativeDuration:0.5

//最大值为1

animations:^{

self.greenView.frame = CGRectMake(0, 200, 100, 50);

}];

//添加

[UIView addKeyframeWithRelativeStartTime:0.5 relativeDuration:1 animations:^{

self.greenView.frame = CGRectMake(200, 200, 100, 50);

}];

} completion:^(BOOL finished) {

self.greenView.frame = CGRectMake(0, 0, 50, 50);

}];



}

-(void)animationWillStart:(NSString *)animationID context:(void *)context{

NSLog(@"start %@",animationID);

}

-(void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context{

NSLog(@"end %@",animationID);

}

@end

你可能感兴趣的:(设置动画代理、开始结束响应函数、关键帧动画)