ios动画

来源:互联网 发布:安卓6.0 移动数据开关 编辑:程序博客网 时间:2024/03/28 21:35

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


    // 开始动画

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


    // 设置动画持续时间

    [UIViewsetAnimationDuration:3];


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

    [UIViewanimateWithDuration:2animations:^{

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

    }];

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

    [UIView animateWithDuration:3 animations:^{

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

    }completion:^(BOOL finished) {

       NSLog(@"fdsf");

    }];

    

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

    [UIViewanimateWithDuration:3delay:2options:UIViewAnimationOptionRepeat animations:^{

        // 动画重复次数

        [UIViewsetAnimationRepeatCount:2];

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

           }completion:^(BOOL finished) {

       NSLog(@"fds");

    }];

    

    // 结束动画

    [UIViewcommitAnimations];



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

   // 属性动画

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

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

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

    animation.duration = 3;

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

    

    

 

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

   CGFloat centerx = self.green.center.x;

   CGFloat centery = self.green.center.y;

    keyFrameAnimation.values = [NSArrayarrayWithObjects:[NSValuevalueWithCGPoint:CGPointMake(centerx, centery)],[NSValuevalueWithCGPoint:CGPointMake(centerx-10, centery)],[NSValuevalueWithCGPoint:CGPointMake(centerx, centery)],[NSValuevalueWithCGPoint:CGPointMake(centerx+10, centery)],[NSValuevalueWithCGPoint:CGPointMake(centerx, centery)],[NSValuevalueWithCGPoint:CGPointMake(centerx-10, centery)],[NSValuevalueWithCGPoint:CGPointMake(centerx, centery)],nil];

    [self.green.layeraddAnimation: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.layeraddAnimation:transition forKey:@"fds"];









0 0
原创粉丝点击