动画

来源:互联网 发布:视觉传达设计软件 编辑:程序博客网 时间:2024/04/19 10:40

--切换两个view的方法

1、UIView封装好的方法

2、切换两个view的动画  CAanimation

    CATransition *animation = [CATransition animation];    animation.delegate = self;    animation.duration = kDuration;    animation.timingFunction = UIViewAnimationCurveEaseInOut;        NSLog(@"button tag is %i",tag);    //上边按钮中的下边四个和下边的两行八个按钮,共12个button的tag    switch (tag) {        case 101://淡化            animation.type = kCATransitionFade;            break;        case 102://推挤            animation.type = kCATransitionPush;            break;        case 103://揭开            animation.type = kCATransitionReveal;            break;        case 104://覆盖            animation.type = kCATransitionMoveIn;            break;        case 201://立方体            animation.type = @"cube";            break;        case 202://吸收            animation.type = @"suckEffect";            break;        case 203://翻转            animation.type = @"oglFlip";            break;        case 204://波纹            animation.type = @"rippleEffect";            break;        case 205://翻页            animation.type = @"pageCurl";            break;        case 206://反翻页            animation.type = @"pageUnCurl";            break;        case 207://镜头开            animation.type = @"cameraIrisHollowOpen";            break;        case 208://镜头关            animation.type = @"cameraIrisHollowClose";            break;        default:            break;    }        switch (self.typeID) {        case 0://            animation.subtype = kCATransitionFromLeft;            break;        case 1:            animation.subtype = kCATransitionFromBottom;            break;        case 2:            animation.subtype = kCATransitionFromRight;            break;        case 3:            animation.subtype = kCATransitionFromTop;            break;        default:            break;    }    self.typeID += 1;    if (self.typeID > 3) {        self.typeID = 0;    }        NSUInteger green = [[self.view subviews] indexOfObject:self.greenView];    NSUInteger blue = [[self.view subviews] indexOfObject:self.blueView];    [self.view exchangeSubviewAtIndex:green withSubviewAtIndex:blue];            [[self.view layer] addAnimation:animation forKey:@"animation"];

--关于CAanimation

  1、路径动画  
  
//贝塞尔路径,路径动画    UIBezierPath *movePath = [UIBezierPath bezierPath];    [movePath moveToPoint:fromPoint];    CGPoint toPoint = CGPointMake(fromPoint.x +100 , fromPoint.y ) ;    [movePath addLineToPoint:toPoint];    CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"];    moveAnim.path = movePath.CGPath;
2、旋转动画
       

    CABasicAnimation *TransformAnim2 = [CABasicAnimation animationWithKeyPath:@"transform"];    TransformAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];    TransformAnim2.toValue = [NSValue valueWithCATransform3D: CATransform3DMakeTranslation(0, 0, 10)];    TransformAnim2.cumulative = NO;    TransformAnim2.duration = 1.45f;    TransformAnim2.repeatCount = 1;    TransformAnim2.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];


3、 缩放动画

 

    CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];    scaleAnimation.fromValue = [NSNumber numberWithFloat:1.0];    scaleAnimation.toValue = [NSNumber numberWithFloat:0.8];    scaleAnimation.duration = 0.45f;    scaleAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

  

4  、动画组

    

    CAAnimationGroup *animGroup = [CAAnimationGroup animation];    animGroup.animations = [NSArray arrayWithObjects: TransformAnim,scaleAnimation                            ,nil];    animGroup.autoreverses = NO;    animGroup.duration = 0.45f;

5、添加


 [self.flyView.layer addAnimation:animGroup forKey:nil];   

6、高仿淘宝更多 --图片向后移动动画

  

    CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"transform"];    CATransform3D rotateTransform = CATransform3DMakeRotation(30*3.14/180, -1, 0, 0);    CATransform3D scaleTransform = CATransform3DMakeScale(0.8, 0.8, 0.8);    CATransform3D positionTransform = CATransform3DMakeTranslation(0, 0, 0); //位置移动    CATransform3D combinedTransform = CATransform3DConcat(rotateTransform, scaleTransform); //Concat就是combine的意思    combinedTransform = CATransform3DConcat(combinedTransform, positionTransform); //再combine一次把三个动作连起来        [anim setFromValue:[NSValue valueWithCATransform3D:CATransform3DIdentity]]; //放在3D坐标系中最正的位置    [anim setToValue:[NSValue valueWithCATransform3D:combinedTransform]];    [anim setDuration:1.0f];    //添加动画    [self.flyView.layer addAnimation:anim forKey:nil];    //设置最后结果    [self.flyView.layer setTransform:combinedTransform];  //如果没有这句,layer执行完动画又会返回最初的state


+苹果删除效果

CGAffineTransform wobbleLeft = CGAffineTransformMakeRotation(rotation); 
CGAffineTransform wobbleRight = CGAffineTransformMakeRotation(-rotation); 
[UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.2];
[UIView setAnimationDelegate:self]; [UIView setAnimationRepeatCount:99999999];
 cellView.transform = wobblesLeft ? wobbleRight : wobbleLeft; wobblesLeft = !wobblesLeft; 
[UIView commitAnimations];

设置转动锚点 

 _hammerImageView.center = CGPointMake(( (UIButton *)sender ).center.x + 70, ( (UIButton *)sender ).center.y - 30);  //设置uiview的锚点,范围为 ( 0-1 )  _hammerImageView.alpha = 1;  _hammerImageView.layer.anchorPoint = CGPointMake(1, 1); _hammerImageView.transform = CGAffineTransformIdentity; UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:1]; //使uiview进行旋转,旋转的度数为弧度。 _hammerImageView.transform = CGAffineTransformMakeRotation(DEGREE_2_RADIAN(-45)); [UIView commitAnimations];

+图片动画效果

 

UIImageView *imageView = [[UIImageView alloc] initWithFrame:btn.frame];        imageView.animationImages = _moleImageArray;        imageView.animationDuration = 1;        [self.view addSubview:imageView];


相关理论详解:http://blog.sina.com.cn/s/blog_8f5097be0101b91z.html
 优秀实例代码:http://blog.csdn.net/totogo2010/article/details/8606089
     

0 0
原创粉丝点击