CAShapeLayer

Horus-iOS·2022년 9월 21일
0

https://developer.apple.com/documentation/quartzcore/cashapelayer

A layer that draws a cubic Bezier spline in its coordinate space.

좌표 공간에 3차원 베지어 스플라인을 그리는 레이어입니다.

Declaration

class CAShapeLayer : CALayer

Overview

모양은 레이어의 컨텐츠와 첫 번째 하위레이어 사이에서 구성됩니다. 모양은 안티알리아스가 적용되어 그려질 것이며, 가능할 때마다 레졸루션 독립성 보존을 위한 래스터라이징 전에 스크린 공간으로 맵핑될 것입니다. 그러나 코어 이미지 필터와 같은 레이어에 적용된 혹은 조상에 적용된 특정 이미지 처리 작업은 로컬 공간 좌표에서 강제로 래스터화될 것입니다.

Listing 1은 복잡한 합성 경로를 어떻게 빌드하는지 보여주며, 모양 레이어를 사용해서 표시합니다. 이 예시에서 연속적으로 변형된 타원이 꽃 모양을 형성합니다. 경로를 표시하는 모양 레이어는 노란색fillColor를 채우는 것으로부터 꽃잎을 오버랩하지 않도록fillRuleevenOdd로 설정됩니다.

Listing 1 Creating a stylized flower with a shape layer

let width: CGFloat = 640
let height: CGFloat = 640
     
let shapeLayer = CAShapeLayer()
shapeLayer.frame = CGRect(x: 0, y: 0,
                          width: width, height: height)
     
let path = CGMutablePath()
     
stride(from: 0, to: CGFloat.pi * 2, by: CGFloat.pi / 6).forEach {
    angle in 
    var transform  = CGAffineTransform(rotationAngle: angle)
        .concatenating(CGAffineTransform(translationX: width / 2, y: height / 2))
    
    let petal = CGPath(ellipseIn: CGRect(x: -20, y: 0, width: 40, height: 100),
                       transform: &transform)
    
    path.addPath(petal)
}
    
shapeLayer.path = path
shapeLayer.strokeColor = UIColor.red.cgColor
shapeLayer.fillColor = UIColor.yellow.cgColor
shapeLayer.fillRule = kCAFillRuleEvenOdd

Figure 1 shows the resulting shape layer.
Figure 1 Composite path displayed in a shape layer

Note
모양 래스터화는 정확도보다 속도를 선호할 수 있습니다. 예를 들어 다중으로 교차하는 경로 세그먼트를 갖는 픽셀은 정확한 결과를 보이지 않을 것입니다.

0개의 댓글