Core Animation

来源:互联网 发布:python和java 编辑:程序博客网 时间:2024/05/16 01:16

1、Core Animation之基础介绍

http://blog.csdn.net/totogo2010/article/details/8604719

2、Core Animation之简单使用CALayer

http://blog.csdn.net/totogo2010/article/details/8605092

3、Core Animation之多种动画效果

http://blog.csdn.net/totogo2010/article/details/8606089

4、CoreAnimation编程指南

http://www.dreamingwish.com/dream-2012/coreanimation-programming-guide-table-of-contents.html

5、移动

- (void)viewDidLoad{    [super viewDidLoad];// Do any additional setup after loading the view, typically from a nib.    UIImage *xcodeImage = [UIImage imageNamed:@"Xcode.png"];    self.xcodeImageView = [[UIImageView alloc] initWithImage:xcodeImage];    //设置图片的Frame    [self.xcodeImageView setFrame:CGRectMake(0.0f,0.0f, 100.0f, 100.0f)];    self.view.backgroundColor = [UIColor whiteColor];    [self.view addSubview:self.xcodeImageView];}-(void) viewDidAppear:(BOOL)paramAnimated{    [super viewDidAppear:paramAnimated];    //从左上角开始    [self.xcodeImageView setFrame:CGRectMake(0.0f,0.0f, 100.0f, 100.0f)];    /*调用 beginAnimations:context:方法来启动一个动画后,动画并不会立即被执行,直到你调用 UIView 类的 commitAnimations 类方法。对一个视图对象执行的介于 beginAnimations:context:方法跟 commitAnimations 方法之间的操作(例如移动)会在 commitAnimations 被执行后才会生效。     启动一个动画块。任何在此类方法调用后你提交给视图的动画属性的改变会在动画提交后得到执行。     */    [UIView beginAnimations:@"xcodeImageViewAnimation" context:self.xcodeImageView];    //设置动画时间为5s    [UIView setAnimationDuration:5.0f];    //接受动画代理    [UIView setAnimationDelegate:self];    //设置消息发送到动画代表当动画停止。如果你指定一个动画代表一个开始/提交动画,你用这个方法来指定选择器被调用后,动画结束。这种方法并没有做任何事情如果调用外部的一个动画块。它必须被调用beginAnimations和commitAnimations方法之间。这个选择器默认设置为NULL。    [UIView setAnimationDidStopSelector:@selector(imageViewDidStop:finished:context:)];    /* 设置Frame在右下角 */    [self.xcodeImageView setFrame:CGRectMake(200.0f,350.0f,100.0f,100.0f)];    //提交动画    [UIView commitAnimations]; }-(void)imageViewDidStop:(NSString*)paramAnimationID finished:(NSNumber*)paramFinished context:(void*)paramContext{    NSLog(@"AnimationID = %@\n",paramAnimationID);    UIImageView *contextImageView = (__bridge UIImageView *)(paramContext);    NSLog(@"contextImageView = %@",contextImageView);    [contextImageView removeFromSuperview];}
- (void)viewDidLoad{    [super viewDidLoad];    UIImage *xcodeImage = [UIImage imageNamed:@"Xcode.png"];    self.xcodeImageView1 = [[UIImageView alloc] initWithImage:xcodeImage];    self.xcodeImageView2 = [[UIImageView alloc] initWithImage:xcodeImage];    //初始化图片    [xcodeImageView1 setFrame:CGRectMake(0.0f, 0.0f,100.0f, 100.0f)];    [xcodeImageView2 setFrame:CGRectMake(220.0f, 350.0f, 100.0f,100.0f)];    self.view.backgroundColor = [UIColor whiteColor];    [self.view addSubview:self.xcodeImageView1];    [self.view addSubview:self.xcodeImageView2];}- (void) startTopLeftImageViewAnimation{    [self.xcodeImageView1 setFrame:CGRectMake(0.0f,0.0f, 100.0f, 100.0f)];    //设置透明度为1    [self.xcodeImageView1 setAlpha:1.0f];    [UIView beginAnimations:@"xcodeImageView1Animation" context:(void *)self.xcodeImageView1];    /* 3 seconds animation */    [UIView setAnimationDuration:3.0f];    /* Receive animation delegates */    [UIView setAnimationDelegate:self];    //动画停止时候调用imageViewDidStop方法    [UIView setAnimationDidStopSelector:@selector(imageViewDidStop:finished:context:)];    /* End at the bottom right corner */    [self.xcodeImageView1 setFrame:CGRectMake(220.0f,350.0f, 100.0f, 100.0f)];    //设置透明度为0不可见    [self.xcodeImageView1 setAlpha:0.0f];    [UIView commitAnimations];}- (void)imageViewDidStop:(NSString *)paramAnimationID finished:(NSNumber *)paramFinished                 context:(void *)paramContext{    UIImageView *contextImageView = (UIImageView *)paramContext;    //移除视图    [contextImageView removeFromSuperview];}- (void) startBottomRightViewAnimationAfterDelay:(CGFloat)paramDelay{    /* Start from bottom right corner */    [self.xcodeImageView2 setFrame:CGRectMake(220.0f,350.0f, 100.0f, 100.0f)];    [self.xcodeImageView2 setAlpha:1.0f];    [UIView beginAnimations:@"xcodeImageView2Animation" context:(void *)self.xcodeImageView2];    /* 3 seconds animation */    [UIView setAnimationDuration:3.0f];    //动画推迟时间    [UIView setAnimationDelay:paramDelay];    /* Receive animation delegates */    [UIView setAnimationDelegate:self];    [UIView setAnimationDidStopSelector: @selector(imageViewDidStop:finished:context:)];    /* End at the top left corner */    [self.xcodeImageView2 setFrame:CGRectMake(0.0f,0.0f, 100.0f, 100.0f)];    [self.xcodeImageView2 setAlpha:0.0f];    [UIView commitAnimations];}- (void) viewDidAppear:(BOOL)paramAnimated{    [super viewDidAppear:paramAnimated];    [self startTopLeftImageViewAnimation];    [self startBottomRightViewAnimationAfterDelay:2.0f];}- (void)viewDidUnload{    [super viewDidUnload];    self.xcodeImageView1 = nil;    self.xcodeImageView2 = nil;}

6、缩放

- (void) viewDidAppear:(BOOL)paramAnimated{ [super viewDidAppear:paramAnimated];    /* Place the image view at the center of the view of this view controller */    self.xcodeImageView.center = self.view.center;    //设置转换标识    self.xcodeImageView.transform = CGAffineTransformIdentity;    /* Begin the animation */    [UIView beginAnimations:nil context:NULL];    /* Make the animation 5 seconds long */    [UIView setAnimationDuration:5.0f];    //图形放大两倍    self.xcodeImageView.transform = CGAffineTransformMakeScale(2.0f, 2.0f);    /* Commit the animation */    [UIView commitAnimations];}

7、旋转

- (void) viewDidAppear:(BOOL)paramAnimated{ [super viewDidAppear:paramAnimated];    self.xcodeImageView.center = self.view.center;    /* Begin the animation */    [UIView beginAnimations:@"clockwiseAnimation" context:NULL];    /* Make the animation 5 seconds long */    [UIView setAnimationDuration:5.0f];    [UIView setAnimationDelegate:self];    //停止动画时候调用clockwiseRotationStopped方法    [UIView setAnimationDidStopSelector:@selector(clockwiseRotationStopped:finished:context:)];    //顺时针旋转90度    self.xcodeImageView.transform = CGAffineTransformMakeRotation((90.0f * M_PI) / 180.0f);    /* Commit the animation */    [UIView commitAnimations];}- (void)clockwiseRotationStopped:(NSString *)paramAnimationID finished:(NSNumber *)paramFinished                         context:(void *)paramContext{    [UIView beginAnimations:@"counterclockwiseAnimation"context:NULL];    /* 5 seconds long */    [UIView setAnimationDuration:5.0f];    /* 回到原始旋转 */    self.xcodeImageView.transform = CGAffineTransformIdentity;    [UIView commitAnimations];}


0 0
原创粉丝点击