Light's Blog

The best or nothing.

iOS知识小集-170703

| Comments

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
- (CAKeyframeAnimation *)circleShake {
  if (!_circleShake) {
    CGFloat baseX = self.circleMask.position.x;
    _circleShake = [CAKeyframeAnimation animationWithKeyPath:@"position.x"];
    _circleShake.keyTimes = @[
      @0,
      @(0.1 / 0.8),
      @(0.2 / 0.8),
      @(0.3 / 0.8),
      @(0.5 / 0.8),
      @(0.76 / 0.8)
    ];
    _circleShake.values = @[
      @(baseX),
      @(baseX - 11),
      @(baseX + 11),
      @(baseX - 11),
      @(baseX + 11),
      @(baseX)
    ];
    _circleShake.duration = 0.8;
    _circleShake.removedOnCompletion = YES;
    _circleShake.fillMode = kCAFillModeForwards;
  }
  return _circleShake;
}

Identify CAAnimation within the aniamtionDidStop delegate

The animation is copied before being added to the layer, so any subsequent modifications to anim will have no affect unless it is added to another layer.
Use animationForKey: to identify.
Create one animation and add to multiple layers.

Apply changes when animation finished

1
2
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;

Resume changes when animation finished

1
2
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeBackwards;

Use CAAnimationGroup to run animations cocurrently

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
- (CAAnimationGroup *)circleBig {
  if (!_circleBig) {
    _circleBig = [CAAnimationGroup animation];
    CABasicAnimation *circleBig =
        [CABasicAnimation animationWithKeyPath:@"path"];
    circleBig.fromValue = (__bridge id)self.circleMask.path;
    circleBig.toValue =
        (__bridge id)[UIBezierPath bezierPathWithArcCenter:self.centerPoint
                                                    radius:12.5
                                                startAngle:0
                                                  endAngle:M_PI * 2
                                                 clockwise:YES]
            .CGPath;
    circleBig.duration = self.spreadDuration;
    circleBig.removedOnCompletion = NO;
    circleBig.fillMode = kCAFillModeForwards;
    circleBig.timingFunction = [CAMediaTimingFunction
        functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    CABasicAnimation *changeWidth =
        [CABasicAnimation animationWithKeyPath:@"lineWidth"];
    changeWidth.fromValue = @(self.circleMask.lineWidth);
    changeWidth.toValue = @(5);
    changeWidth.duration = self.spreadDuration;
    changeWidth.removedOnCompletion = NO;
    changeWidth.fillMode = kCAFillModeForwards;
    _circleBig.animations = @[ circleBig, changeWidth ];
  }
  return _circleBig;
}

TabBar背景设为透明色

1
2
3
[[UITabBar appearance] setShadowImage:[WWImageUtil imageWithColor:[UIColor clearColor]]];
[[UITabBar appearance] setBackgroundImage:[WWImageUtil imageWithColor:[UIColor clearColor]]];
[UITabBar appearance].translucent = YES;

TabBar去除黑线

1
[[UITabBar appearance] setClipsToBounds:YES];

self.title

self.title:同时设置导航栏和tabBar的title;
self.navigationItem.title:设置导航栏title;
self.tabBarItem.title:设置tabBartitle。

InHouse 和 Debug配置不同

Comments