您的位置:首页 > 移动开发 > IOS开发

ios动画

2015-10-16 19:42 393 查看
  // 
动画分为两种UIView层动画 CALayer层动画。

    //  UIView层动画分为两种类型:
    // 1.属性动画
    // 2.过渡动画

    //属性动画之block
//    [UIView animateWithDuration:1 animations:^{
//        self.AView.alpha = 0.3;
//    }];
//    [UIView animateWithDuration:3 animations:^{
//        self.AView.transform = CGAffineTransformMakeRotation(M_PI_4);
//        self.AView.backgroundColor = [UIColor grayColor];
//        self.AView.bounds = CGRectMake(0, 0, 100, 100);
//    } completion:^(BOOL finished) {
//        NSLog(@"结束");
//    }];
    
//    [UIView animateWithDuration:2 delay:2 options:UIViewAnimationOptionAllowUserInteraction  animations:^{
//        self.AView.transform = CGAffineTransformMakeRotation(M_PI_4);
//                self.AView.backgroundColor = [UIColor grayColor];
//                self.AView.bounds = CGRectMake(0, 0, 100, 100);
//    } completion:^(BOOL finished) {
//        self.AView.backgroundColor = [UIColor redColor];
//    }];
    
//      [UIView animateWithDuration:2 delay:2 usingSpringWithDamping:0.1 initialSpringVelocity:2 options:UIViewAnimationOptionAllowUserInteraction animations:^{
//          self.AView.transform = CGAffineTransformMakeRotation(M_PI_4);
//                          self.AView.backgroundColor = [UIColor grayColor];
//                          self.AView.bounds = CGRectMake(0, 0, 100, 100);
//      } completion:^(BOOL finished) {
//      }];

//  普通翻页效果

 UIView *containerView =
self.view.superview;
    [UIView
transitionWithView:containerView
duration:2
options:UIViewAnimationOptionTransitionCurlUp
animations:^{
        [self.view
removeFromSuperview] ;
        [containerView addSubview:XVC.view];
    } completion:^(BOOL finished) {
    }];

  //  CAlayer层在做属性动画时
并不是所有的属性都可以做动画 只有属性后面带Animatable的才可以做动画。


 CABasicAnimation *basicAnimation = [CABasicAnimation
animationWithKeyPath:@"backgroundColor"];
    basicAnimation.duration =
2;
    basicAnimation.fromValue = (__bridge
id)([UIColor
yellowColor].CGColor);
    basicAnimation.toValue = (__bridge
id)([UIColor
redColor].CGColor);
    [self.AView.layer
addAnimation:basicAnimation
forKey:@"BS"];

//类似于QQ的弹框的抖动效果

   CAKeyframeAnimation *keyFrameAnimation = [CAKeyframeAnimation
animationWithKeyPath:@"position.x"];
    CGFloat x =
self.AView.center.x;
    CGFloat leftX = x -
10;
    CGFloat rightX = x +
10;
    NSNumber *X = [NSNumber
numberWithFloat:x];
    NSNumber *leftx = [NSNumber
numberWithFloat:leftX];
    NSNumber *righty = [NSNumber
numberWithFloat:rightX];
    NSArray *values =
@[X,leftx,X,righty,X,leftx,X,righty,X];
    keyFrameAnimation.values = values;
    [self.AView.layer
addAnimation:keyFrameAnimation
forKey:@"keyFrame"];

CATransition 动画具有方块翻页效果
 CATransition *catransition = [CATransition
animation];
    //  1获取self.view.superView
    UIView *view =
self.view.superview;
    catransition.type =
@"cube";
    catransition.duration =
3;
    catransition.startProgress =
0.3; //
开始动画
    catransition.endProgress =
0.8; //
结束动画
    //  2给self.view.superView添加动画
    [view.layer
addAnimation:catransition
forKey:@"catransition"];
    //  3移除原来的View,添加新的View
    [self.view
removeFromSuperview];
    XViewController *XVC = [self.storyboard
instantiateViewControllerWithIdentifier:@"X"];
    [view addSubview:XVC.view];

CAAnimationGroup可融合前面的动画 做出多动画效果

CAAnimationGroup *group = [CAAnimationGroup
animation];
    
    CABasicAnimation *basicAnimation = [CABasicAnimation
animationWithKeyPath:@"backgroundColor"];
    
    basicAnimation.duration =
2;
    basicAnimation.fromValue = (__bridge
id)([UIColor
yellowColor].CGColor);

    CAKeyframeAnimation *keyFrameAnimation = [CAKeyframeAnimation
animationWithKeyPath:@"position.x"];
    CGFloat x =
self.AView.center.x;
    CGFloat leftX = x -
10;
    CGFloat rightX = x +
10;
    NSNumber *X = [NSNumber
numberWithFloat:x];
    NSNumber *leftx = [NSNumber
numberWithFloat:leftX];
    NSNumber *righty = [NSNumber
numberWithFloat:rightX];
    
    NSArray *values =
@[X  ,leftx,X,righty,X,leftx,X,righty,X];
    
    keyFrameAnimation.values = values;

    group.duration =
2;
    
    group.animations =
@[basicAnimation,keyFrameAnimation];
    [self.AView.layer
addAnimation:group forKey:@"group"];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: