ios动画

    ios4.0以前使用的设置动画的方法,平时不建议用,偶尔有需要的话可以用


    // 开始动画

    [UIView beginAnimations:@"fdsf" context:nil];


    // 设置动画持续时间

    [UIView setAnimationDuration:3];


    // 设置动画持续时间和动画内容

    [UIView animateWithDuration:2 animations:^{

        self.green.center = CGPointMake(100, 100);

    }];

    // 设置动画持续时间和动画内容以及动画完成后做什么事

    [UIView animateWithDuration:3 animations:^{

        self.green.center = CGPointMake(100, 100);

    } completion:^(BOOL finished) {

        NSLog(@"fdsf");

    }];

    

    // 设置动画持续时间 推迟几秒开始 选择权 动画内容 动画结束后做什么事

    [UIView animateWithDuration:3 delay:2 options:UIViewAnimationOptionRepeat  animations:^{

        // 动画重复次数

        [UIView setAnimationRepeatCount:2];

     self.green.center = CGPointMake(100, 100);

           } completion:^(BOOL finished) {

        NSLog(@"fds");

    }];

    

    // 结束动画

    [UIView commitAnimations];



   以下是经常使用的三种种动画:CA动画. (CA是效果不会改变属性值)

   // 属性动画

   CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"bounds"];

    animation.fromValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 0, 0)];

    animation.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 300, 200)];

    animation.duration = 3;

    [self.view.layer addAnimation:animation forKey:@"hello"];

    

    

 

  CAKeyframeAnimation *keyFrameAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];

    CGFloat centerx = self.green.center.x;

    CGFloat centery = self.green.center.y;

    keyFrameAnimation.values = [NSArray arrayWithObjects:[NSValue valueWithCGPoint:CGPointMake(centerx, centery)],[NSValue valueWithCGPoint:CGPointMake(centerx-10, centery)],[NSValue valueWithCGPoint:CGPointMake(centerx, centery)],[NSValue valueWithCGPoint:CGPointMake(centerx+10, centery)],[NSValue valueWithCGPoint:CGPointMake(centerx, centery)],[NSValue valueWithCGPoint:CGPointMake(centerx-10, centery)],[NSValue valueWithCGPoint:CGPointMake(centerx, centery)], nil];

    [self.green.layer addAnimation:keyFrameAnimation forKey:@"fds"];



   // 过渡动画 (一般设置一个容器在这个容器内做页面的跳转)

   

 CATransition *transition = [CATransition  animation];

    transition.type = @"cube";

    transition.subtype = kCATransitionFromRight;

    transition.duration = 3;

    transition.startProgress = 0;

    transition.endProgress = 0.8;

    [self.red.layer addAnimation:transition forKey:@"fds"];









  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值