iOS CoreAnimation教程 第三篇

今天主要讲解图层的lineJoin miterLimit 属性。

lineJoin 连接点类型,对应曲线节点的显示样式。可能会受到miterLimit影响。看四个例子


kCALineJoinMiter样式
    CAShapeLayer * Star = [CAShapeLayer layer];
    Star.frame       = CGRectMake(102, 254.56, 183.74, 193.44);
    Star.lineCap     = kCALineCapRound;
    Star.lineJoin    = kCALineJoinMiter;
    Star.miterLimit  = 4;
    Star.fillColor   = [UIColor colorWithRed:0.847 green: 0.847 blue:0.847 alpha:1].CGColor;
    Star.strokeColor = [UIColor colorWithRed:0.592 green: 0.592 blue:0.592 alpha:1].CGColor;
    Star.lineWidth   = 15;
kCALineJoinRound样式
    CAShapeLayer * Star = [CAShapeLayer layer];
    Star.frame       = CGRectMake(102, 254.56, 183.74, 193.44);
    Star.lineCap     = kCALineCapRound;
    Star.lineJoin    = kCALineJoinRound;
    Star.fillColor   = [UIColor colorWithRed:0.847 green: 0.847 blue:0.847 alpha:1].CGColor;
    Star.strokeColor = [UIColor colorWithRed:0.592 green: 0.592 blue:0.592 alpha:1].CGColor;
    Star.lineWidth   = 15;
    Star.path        = [self StarPath].CGPath;
kCALineJoinBevel样式
    CAShapeLayer * Star = [CAShapeLayer layer];
    Star.frame       = CGRectMake(102, 254.56, 183.74, 193.44);
    Star.lineCap     = kCALineCapRound;
    Star.lineJoin    = kCALineJoinBevel;
    Star.fillColor   = [UIColor colorWithRed:0.847 green: 0.847 blue:0.847 alpha:1].CGColor;
    Star.strokeColor = [UIColor colorWithRed:0.592 green: 0.592 blue:0.592 alpha:1].CGColor;
    Star.lineWidth   = 15;
    Star.path        = [self StarPath].CGPath;
miterLimit 影响lineJoin样式
    CAShapeLayer * Star = [CAShapeLayer layer];
    Star.frame       = CGRectMake(102, 254.56, 183.74, 193.44);
    Star.lineCap     = kCALineCapRound;
    Star.lineJoin    = kCALineJoinMiter;
    Star.miterLimit  = 1;
    Star.fillColor   = [UIColor colorWithRed:0.847 green: 0.847 blue:0.847 alpha:1].CGColor;
    Star.strokeColor = [UIColor colorWithRed:0.592 green: 0.592 blue:0.592 alpha:1].CGColor;
    Star.lineWidth   = 15;
    Star.path        = [self StarPath].CGPath;

总结:miterLimit是最大斜接长度,只有lineJoin属性为kCALineJoinMiter时miterLimit才有效,当衔接角度太小时,斜接长度就会很大,如果设置了 miterLimit并且当斜接长度大于这个值时,便会对应裁切掉多余区域。就像上面第四种情况。

你可能感兴趣的:(iOS CoreAnimation教程 第三篇)