몇 가지 특별한 계층 애니메이션

아이폰 OS 특별한 층의 프레임 워크에서이 코어 애니메이션, 그들은 사진, 원치 않는 프레임 애니메이션을 사용하지 않고 매우 눈부신 애니메이션 효과를 사용할 수 있도록하는 경향이있다. 여기에서 우리는 세 가지 일반적인 레이어 애니메이션을 살펴 CAReplicatorLayer, CAEmitterLayer 및 CAGradientLayer 있습니다.

우선, 층 애니메이션 복사 CAReplicatorLayer

CAReplicatorLayer 층은 자신의 하위 레이어를 복제 할 수 있으며, 하부층 및 가동 층 중 원고의 복사는 동일한 효과를 갖는다. 그런 다음 몇 가지 속성을 설정, 당신은 매우 강력합니다, 시원한 효과를 완료 할 수 있습니다. .

## 이펙트 1 :

심장 .gif 참고 : 애니메이션

## 구현 :
우리는 사랑의 길을 가야 1. 먼저, UIBezierPath이 경로를 만들기 위해;

      
      
1
4
5
6
(7)
8
9
(10)
(11)
(12)
(13)
(14)
(15)
(16)
(17)
(18)
(19)
(20)
      
      
+ (CGPathRef) heartPath
{
CGFloat W = 25;
CGFloat marginX = 10;
CGFloat marginY = 15 / 25.0 * W;
CGFloat 공간 = 5 / 25.0 * W;
UIBezierPath bezierPath * = [UIBezierPath 신품;
[bezierPath moveToPoint (CGPointMake (marginX + W * 2 * 4 + W 공간))];
[bezierPath addQuadCurveToPoint:CGPointMake(marginX, W * 2) controlPoint:CGPointMake(W, W * 4 - space)];
[bezierPath addCurveToPoint:CGPointMake(marginX + W * 2, W * 2) controlPoint1:CGPointMake(marginX, marginY) controlPoint2:CGPointMake(marginX + W * 2, marginY)];
[bezierPath addCurveToPoint:CGPointMake(marginX + W * 4, W * 2) controlPoint1:CGPointMake(marginX + W * 2, marginY) controlPoint2:CGPointMake(marginX + W * 4, marginY)];
[bezierPath addQuadCurveToPoint:CGPointMake(marginX + W * 2, W * 4 + space) controlPoint:CGPointMake(marginX * 2 + W * 3, W * 4 - space)];
[bezierPath closePath];
CGAffineTransform T = CGAffineTransformMakeScale(3.0, 3.0);
return CGPathCreateCopyByTransformingPath(bezierPath.CGPath, &T);
}

2.创建CAReplicatorLayer,添加上CAKeyframeAnimation动效;

      
      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
      
      
+ (CALayer *)replicatorLayer_Heart{
CAReplicatorLayer *replicatorLayer = [CAReplicatorLayer new];
replicatorLayer.frame = CGRectMake(0, 0, 200, 200);
// replicatorLayer.backgroundColor = [UIColor colorWithWhite:0 alpha:0.75].CGColor;
CALayer *subLayer = [CALayer new];
subLayer.bounds = CGRectMake(60, 105, 10, 10);
subLayer.backgroundColor = [UIColor colorWithWhite:0.8 alpha:1.0].CGColor;
subLayer.borderColor = [UIColor colorWithWhite:1.0 alpha:1.0].CGColor;
subLayer.borderWidth = 1.0;
subLayer.cornerRadius = 5.0;
subLayer.shouldRasterize = YES;
subLayer.rasterizationScale = [UIScreen mainScreen].scale;
[replicatorLayer addSublayer:subLayer];
CAKeyframeAnimation *move = [CAKeyframeAnimation animationWithKeyPath:@"position"];
move.path = [self heartPath];
move.repeatCount = INFINITY;
move.duration = 6.0;
// move.autoreverses = YES;
[subLayer addAnimation:move forKey:nil];
replicatorLayer.instanceDelay = 6/50.0;
replicatorLayer.instanceCount = 50;
replicatorLayer.instanceColor = [UIColor orangeColor].CGColor;
replicatorLayer.instanceGreenOffset = -0.03;
return replicatorLayer;
}

3.创建一个UIView,将CAReplicatorLayer添加上去。

      
      
1
2
3
4
5
6
7
8
      
      
- (void)setReplicatorLayerType:(YUReplicatorLayerType)replicatorLayerType
{
CGFloat width = 100;
UIView *aniView = [[UIView alloc] initWithFrame:CGRectMake(0, 150, width, width)];
[self.view addSubview:aniView];
[aniView.layer addSublayer: [YUReplicatorAnimation replicatorLayerWithType:replicatorLayerType]];
self.view.backgroundColor = [UIColor grayColor];
}

##CAReplicatorLayer动画效果合集:

CAReplicatorLayer .gif 중요 애니메이션 컬렉션

##实现:点击下载demo源代码

二、粒子动画 CAEmitterLayer

CAEmitterLayer 是一个高性能的粒子引擎,被用来创建复杂的粒子动画如:烟雾,火,雨等效果,并且很好地控制了性能。

CAEmitterLayer 看上去像是许多 CAEmitterCell 的容器,这些 CAEmitterCell 定义了一个例子效果。你将会为不同的例子效果定义一个或多个 CAEmitterCell 作为模版,同时 CAEmitterLayer 负责基于这些模版实例化一个粒子流。一个 CAEmitterCell 类似于一个 CALayer :它有一个 contents 属性可以定义为一个 CGImage ,另外还有一些可设置属性控制着表现和行为。

##下雪效果:
눈 .gif 중요

三、渐变层 CAGradientLayer

使用CAGradientLayer可以实现色差动画效果。

##效果:

그라데이션 .gif 중요

##主要实现代码:

      
      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
      
      
- (void)showLoadingInView:(UIView *)view text:(NSString *)text
{
[view addSubview:self];
if (text) {
self.text = text;
}
[self sizeToFit];
// 创建渐变效果的layer
CAGradientLayer *graLayer = [CAGradientLayer layer];
graLayer.frame = self.bounds;
graLayer.colors = @[(__bridge id)[[UIColor greenColor] colorWithAlphaComponent:0.3].CGColor,
(__bridge id)[UIColor yellowColor].CGColor,
(__bridge id)[[UIColor yellowColor] colorWithAlphaComponent:0.3].CGColor];
graLayer.startPoint = CGPointMake(0, 0);//设置渐变方向起点
graLayer.endPoint = CGPointMake(1, 0); //设置渐变方向终点
graLayer.locations = @[@(0.0), @(0.0), @(0.1)]; //colors中各颜色对应的初始渐变点
// 创建动画
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"locations"];
animation.duration = 1.0f;
animation.toValue = @[@(0.9), @(1.0), @(1.0)];
animation.removedOnCompletion = NO;
animation.repeatCount = HUGE_VALF;
animation.fillMode = kCAFillModeForwards;
[graLayer addAnimation : 애니메이션 forKey : @ "xindong"];
// textLabel라는의 graLayer 마스크로 설정
self.layer.mask = graLayer;
}

데모 다운로드

다운로드 클릭 데모 소스 코드를

개요

아이폰 OS 애니메이션 내가 여전히 배울 수있는 여지가 매우 강력하다. 또한, 쓸 수있는 아주 좋은 장소, 나는 위대한 하나님이 저를 수정할 수 있음을, 내가 수정하려고 바랍니다 감사합니다.

원본 : 큰 열  몇 가지 특별한 계층 애니메이션


추천

출처www.cnblogs.com/wangziqiang123/p/11618214.html