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

//

#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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容