//
#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];
//設(shè)置代理
// [UIView setAnimationDelegate:self];
//開始的響應(yīng)函數(shù)
//[UIView setAnimationWillStartSelector:@selector(animationWillStart:context:)];
//結(jié)束時(shí)響應(yīng)函數(shù)
//? [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
//set函數(shù)放前面
// [UIView setAnimationRepeatCount:2];
//? [UIView setAnimationRepeatAutoreverses:YES];
// [UIView setAnimationDuration:3];
//? [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];//出入速度
// self.greenView.transform = CGAffineTransformRotate(self.greenView.transform, M_1_PI);
//transition動(dòng)畫(翻轉(zhuǎn))過渡效果
//? [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft /*從左往右反轉(zhuǎn)*/forView:self.greenView cache:NO/YES];
// [UIView commitAnimations];
//block動(dòng)畫
/* [UIView animateWithDuration:<#(NSTimeInterval)#> animations:<#^(void)animations#>];
[UIView animateWithDuration:<#(NSTimeInterval)#> animations:<#^(void)animations#> completion:<#^(BOOL finished)completion#>];
[UIView animateWithDuration:<#(NSTimeInterval)#> delay:<#(NSTimeInterval)#> options: 動(dòng)畫效果 animations:<#^(void)animations#> completion:<#^(BOOL finished)completion#>]; */
彈簧震動(dòng)動(dòng)畫
/* [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);
關(guān)鍵幀動(dòng)畫
//創(chuàng)建
[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