(一)Animation -> CAlayer

CALayer 即 UIView 中用于呈现内容的动画部分(可以理解为该部分管理动画,其余部分管理手势响应、其他属性等内容)

关键词:

关键词 说明
anchorPoint 锚点(01,01)
opacity 透明度

anchorPoint : 锚点


渐变色 CAGradientLayer

设置属性:

  • frame 位置
  • startPoint 起始渐变位置(01,01)
  • endPoint 结束渐变位置 (01,01)
  • colors 渐变色组,这里要用CGColor
- (void)creatBackground{
  CGSize size = [UIScreen mainScreen].bounds.size;

  CAGradientLayer *bgLayer = [[CAGradientLayer alloc] init];
  bgLayer.frame = CGRectMake( 0, 0, size.width, size.height);

 CGColorRef starColor = [UIColor colorWithRed:0.4 green:0.4 blue:0.7 alpha:1].CGColor;
  CGColorRef endColor = [UIColor colorWithRed:0 green:0.9 blue:0.7 alpha:1].CGColor;

  bgLayer.startPoint = CGPointMake(0, 0);
  bgLayer.endPoint = CGPointMake(1, 1);

  bgLayer.colors = @[(__bridge id)starColor,(__bridge id)endColor];

  [self.view.layer addSublayer:bgLayer];
}
(一)Animation -> CAlayer_第1张图片
效果图

CAShaperLayer

关键词:UIBezierPath
mask切割,绘制等都可以用

- (void)creatShaperImgView{


  CAShapeLayer* shaperLayer = [[CAShapeLayer alloc] init];

  CGPoint point1 = CGPointMake(0, 0);
  CGPoint point2 = CGPointMake(50, 0);
  CGPoint point3 = CGPointMake(50, 10);
  CGPoint point4 = CGPointMake(65, 10);
  CGPoint point5 = CGPointMake(50, 20);
  CGPoint point6 = CGPointMake(50, 100);
  CGPoint point7 = CGPointMake(0, 100);

  UIBezierPath* path = [UIBezierPath bezierPath];
  [path moveToPoint:point1];
  [path addLineToPoint:point2];
  [path addLineToPoint:point3];
  [path addLineToPoint:point4];
  [path addLineToPoint:point5];
  [path addLineToPoint:point6];
  [path addLineToPoint:point7];
  [path closePath];

  shaperLayer.path = path.CGPath;

  [shaperLayer masksToBounds];

  UIImageView* img = [[UIImageView alloc] initWithFrame:CGRectMake(100, 100, 65, 100)];
  [img setImage:[UIImage imageNamed:@"img.jpg"]];
  img.layer.mask = shaperLayer;

  [self.view addSubview:img];
}
(一)Animation -> CAlayer_第2张图片
效果图

参考:iOS开发之让你的应用“动”起来

  • 绘制Image时会创建新的图层,必须使用masksToBounds属性设置为Yes

你可能感兴趣的:((一)Animation -> CAlayer)