美文网首页
animaiton各种好玩动画·1

animaiton各种好玩动画·1

作者: seventhboy | 来源:发表于2018-01-09 16:31 被阅读54次

第一种,撞边框回弹效果
{
CGMutablePathRef starPath = CGPathCreateMutable();
CGPathMoveToPoint(starPath, NULL, 160.0f, 100.0f);
CGPathAddLineToPoint(starPath, NULL, 100.0f, 280.0f);
CGPathAddLineToPoint(starPath, NULL, 260.0f, 170.0f);
CGPathAddLineToPoint(starPath, NULL, 60.0f, 170.0f);
CGPathAddLineToPoint(starPath, NULL, 220.0f, 280.0f);
CGPathCloseSubpath(starPath);

CAKeyframeAnimation *animation = nil;
animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
[animation setDuration:10.f];
[animation setDelegate:self];
[animation setPath:starPath];
CFRelease(starPath);
starPath = nil;
[[_imageView layer] addAnimation:animation forKey:@"position"];

}

  • (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
    [_drawButton setEnabled:YES];
    }

第二种,来回弹跳效果
{
[UIView beginAnimations:@"Slide Around" context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(viewAnimationDone:)];
[UIView setAnimationRepeatCount:3];
[UIView setAnimationRepeatAutoreverses:YES];

CGPoint center = [[self imageView] center];
center.y += 100;
[[self imageView] setCenter:center];
[UIView commitAnimations];

}

  • (void)viewAnimationDone:(NSString *)name{
    [UIView beginAnimations:@"Show Button" context:nil];
    [[self button] setAlpha:1.0];
    [UIView commitAnimations];
    }

第三种,缩放效果
@property (nonatomic) CALayer *scaleLayer;
[_scaleLayer removeAnimationForKey:@"scaleAnimation"];//删除动画效果

  • (void)initScaleLayer{
    _scaleLayer = [[CALayer alloc] init];
    _scaleLayer.backgroundColor = [UIColor blueColor].CGColor;
    _scaleLayer.frame = CGRectMake(60, 20 + 30, 50, 50);
    _scaleLayer.cornerRadius = 10;
    [self.view.layer addSublayer:_scaleLayer];

    CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    scaleAnimation.fromValue = [NSNumber numberWithFloat:1.0];
    scaleAnimation.toValue = [NSNumber numberWithFloat:1.5];//放大多少倍
    scaleAnimation.autoreverses = YES; //旋转后再旋转到原来的位置
    scaleAnimation.fillMode = kCAFillModeRemoved;
    scaleAnimation.repeatCount = MAXFLOAT;
    scaleAnimation.duration = 0.8;

    [_scaleLayer addAnimation:scaleAnimation forKey:@"scaleAnimation"];
    }
    第四种,翻转效果

  • (void)initGroupLayer{
    CALayer *groupLayer = [[CALayer alloc] init];
    groupLayer.frame = CGRectMake(60, 340 + 100 +kYOffset, 50, 50);
    groupLayer.cornerRadius = 10;
    groupLayer.backgroundColor = [UIColor purpleColor].CGColor;
    [self.view.layer addSublayer:groupLayer];

    CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    scaleAnimation.fromValue = [NSNumber numberWithFloat:1.0];
    scaleAnimation.toValue = [NSNumber numberWithFloat:1.5];
    scaleAnimation.autoreverses = YES;
    scaleAnimation.repeatCount = MAXFLOAT;
    scaleAnimation.duration = 0.8;

    CABasicAnimation *moveAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
    moveAnimation.fromValue = [NSValue valueWithCGPoint:groupLayer.position];
    moveAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(320 - 80, groupLayer.position.y)];
    moveAnimation.autoreverses = YES;
    moveAnimation.repeatCount = MAXFLOAT;
    moveAnimation.duration = 2;

    CABasicAnimation *rotateAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.x"];
    rotateAnimation.fromValue = [NSNumber numberWithFloat:0.0];
    rotateAnimation.toValue = [NSNumber numberWithFloat:6.0 * M_PI];
    rotateAnimation.autoreverses = YES;
    rotateAnimation.repeatCount = MAXFLOAT;
    rotateAnimation.duration = 2;

    CAAnimationGroup *groupAnimation = [CAAnimationGroup animation];
    groupAnimation.duration = 2;
    groupAnimation.autoreverses = YES;
    groupAnimation.animations = @[moveAnimation, scaleAnimation, rotateAnimation];
    groupAnimation.repeatCount = MAXFLOAT;

    [groupLayer addAnimation:groupAnimation forKey:@"groupAnimation"];
    }

相关文章

  • animaiton各种好玩动画·1

    第一种,撞边框回弹效果{CGMutablePathRef starPath = CGPathCreateMutab...

  • animaiton各种好玩动画·3

    第一种,渐变色变化CAGradientLayer *gradient = [CAGradientLayer lay...

  • animaiton各种好玩动画·2

    @property (nonatomic) CATransition *transition;//全局变量 aa ...

  • 隐式动画

    1、隐式动画是Core Animaiton的默认行为,当改变图层的动画属性时,能从先前值平滑过渡到新的值,而不是立...

  • 2018-11-28

    1、CABasicAnimation基本动画 各种属性 CABasicAnimation基本动画 各种属性 - u...

  • I.6 特定图层(下)

    AVPlayerLayer 最后我们将讲解AVPlayerLayer。尽管它不是Core Animaiton框架中...

  • instrument工具

    instrument使用 参考:Core Animaiton工具内存泄漏检测instrument使用 路径:Xco...

  • Android自定义视图动画

    本文介绍了View动画的各种效果,并实现自定义动画的效果。主要包括以下部分: 1.view动画-透明动画效果...

  • 你想到的各种好玩,你想不到的各种好玩

    你想到的各种好玩,你想不到的各种好玩 ——读《企鹅、凤梨和穿山甲》 苇眉儿/文 克莱尔·科克-斯塔基是英国的一位作...

  • 一键填充数据

    需求分析 宠物预设上绑定脚本,需要填充很多数据,创建材质球,主要功能为:1.填充Animaiton、材质球、贴图等...

网友评论

      本文标题:animaiton各种好玩动画·1

      本文链接:https://www.haomeiwen.com/subject/yyhgnxtx.html