美文网首页
(一)Animation -> CAlayer

(一)Animation -> CAlayer

作者: 码痞 | 来源:发表于2016-08-23 15:49 被阅读20次

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];
}
效果图

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];
}
效果图

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

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

相关文章

  • (一)Animation -> CAlayer

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

  • Quartz 2D Coordinate Systems

    CALayer Core Animation --------------------------------- ...

  • iOS中实现动画的方式

    关键词:UIView Animation、 CALayer Animation、 UIViewPropertyAn...

  • 动画

    动画 Animation 1.CALayer简介 1.1 CALayer与UIView之间的关系 UIView 能...

  • Core Animation

    基本概念 Core Animation 作用在 CALayer 上,CALayer从概念上类似UIView,每一个...

  • iOS animation动画三个角色(下)

    tags: Animation 上篇iOS animation动画三个角色(上)介绍了主角CALayer和几个动画...

  • Core Animation 一 : CALayer

    基本概念 core animation听起来像是一个负责实现动画效果的框架,实际上并非这样,整个UIKit都建立在...

  • 核心动画CoreAnimation

    核心动画作用在CALayer(Core animation layer)上,CALayer从概念上类似UIView...

  • 第七篇:layer的隐式动画

    在Core Animation之CALayer一集中,我们介绍了Core Animation除了动画之外所有能做到...

  • Core Graphics & Core Animation

    架构图示 Core Graphics Core Animation CALayer presentationLay...

网友评论

      本文标题:(一)Animation -> CAlayer

      本文链接:https://www.haomeiwen.com/subject/etookttx.html