IOS layer常用动画

来源:互联网 发布:青岛网络干部学院 编辑:程序博客网 时间:2024/05/17 09:43

项目中总是需要用到一些动画效果

代码复制过来复制过去找起来很麻烦,直接粘上来以后好找。有的是网上找的,时间久了已经记不得出处了。有人知道就帮忙说下,我好粘帖下别人的链接。

1.过度动画 就是view的渐变效果,偷懒经常使用渐变效果。

#pragma mark - 过度动画-(void) GuoDuAnimation:(UIView *)view{    CATransition *animation = [CATransition animation];        animation.duration = 0.5;        animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];        animation.type = @"Fade";        animation.subtype = kCATransitionFromLeft;        [view.layer addAnimation:animation forKey:nil];    /*     suckEffect(三角)          rippleEffect(水波抖动)          pageCurl(上翻页)          pageUnCurl(下翻页)          oglFlip(上下翻转)     */}

2.移动动画

#pragma mark ===== 横向、纵向移动 ===========-( CABasicAnimation *)moveX:( float )time X:( NSNumber *)x{        CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath : @"transform.translation.x" ]; ///.y 的话就向下移动。        animation. toValue = x;        animation. duration = time;        animation. removedOnCompletion = NO ; //yes 的话,又返回原位置了。        animation. repeatCount = MAXFLOAT ;        animation. fillMode = kCAFillModeForwards ;        return animation;    }

3.闪烁动画

#pragma mark === 永久闪烁的动画 ======-(CABasicAnimation *)opacityForever_Animation:( float )time{        CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath : @"opacity" ]; // 必须写 opacity 才行。        animation. fromValue = [NSNumber numberWithFloat : 1.0f ];        animation. toValue = [NSNumber numberWithFloat : 0.0f ]; // 这是透明度。        animation. autoreverses = YES ;        animation. duration = time;        animation. repeatCount = MAXFLOAT ;        animation. removedOnCompletion = NO ;        animation. fillMode = kCAFillModeForwards ;        animation. timingFunction =[CAMediaTimingFunction functionWithName : kCAMediaTimingFunctionEaseIn ]; /// 没有的话是均匀的动画。        return animation;    }

4.缩放动画

#pragma mark ===== 缩放 -=============-( CABasicAnimation *)scale:( NSNumber *)Multiple orgin:( NSNumber *)orginMultiple durTimes:( float )time Rep:( float )repertTimes{        CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath : @"transform.scale" ];        animation. fromValue = Multiple;        animation. toValue = orginMultiple;        animation. autoreverses = YES ;        animation. repeatCount = repertTimes;        animation. duration = time; // 不设置时候的话,有一个默认的缩放时间 .        animation. removedOnCompletion = NO ;        animation. fillMode = kCAFillModeForwards ;        return   animation;    }

5.组合动画

#pragma mark ===== 组合动画 -=============-( CAAnimationGroup *)groupAnimation:(NSArray *)animationAry durTimes:(float)time Rep:(float)repeatTimes{        CAAnimationGroup *animation = [CAAnimationGroup animation];        animation. animations = animationAry;        animation. duration = time;        animation. removedOnCompletion = NO ;        animation. repeatCount = repeatTimes;        animation. fillMode = kCAFillModeForwards ;        return animation;    }

6.路径动画

#pragma mark ===== 路径动画 -=============-( CAKeyframeAnimation *)keyframeAnimation:(CGMutablePathRef )path durTimes:(float)time Rep:(float)repeatTimes{        CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath : @"position" ];        animation. path = path;        animation. removedOnCompletion = NO ;        animation. fillMode = kCAFillModeForwards ;        animation. timingFunction = [CAMediaTimingFunction functionWithName : kCAMediaTimingFunctionEaseIn ];        animation. autoreverses = NO ;        animation. duration = time;        animation. repeatCount = repeatTimes;        return animation;    }

7.旋转动画

#pragma mark ==== 旋转动画 ======-( CABasicAnimation *)rotation:( float )dur degree:( float )degree direction:( int )direction repeatCount:( int )repeatCount{        CATransform3D rotationTransform = CATransform3DMakeRotation (degree, 0 , 0 , direction);        CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath : @"transform" ];        animation. toValue = [ NSValue valueWithCATransform3D :rotationTransform];        animation. duration   =  dur;        animation. autoreverses = NO ;        animation. cumulative = NO ;        animation. fillMode = kCAFillModeForwards ;        animation. repeatCount = repeatCount;        animation. delegate = self ;        return animation;    }

后续有用的再添加...

0 0
原创粉丝点击