1. 성능 최적화 필렛
APP의 개발에, 그림 또는 반복 둥근. 단지 작은 둥근 그림이 매우 큰 단일 인터페이스의 성능에 미치는 영향,하지만 때이 없을 수 있습니다 경우 상당한 충격 APP의 성능을 때 더 둥근 그림. 우리는 등심은 일반적으로 다음과 같은 방식입니다 설정 :
imageView.layer.cornerRadius = CGFloat (10);
imageView.layer.masks ToBounds = YES;
GPU 열 버퍼이 과정의 렌더링 메커니즘은 현재 화면 밖에 새로운 이러한 작업은 등심에 도달하는 경우, 우리에게 추가적인 성능 손실을 줄 것이다 오프 스크린 렌더링입니다 작업에 버퍼 렌더링 - 수의 부여 빈번한 합병 컨텍스트는 사용자 경험의 열한 지금 거시적 표면 특성이 끊김 것 빈번한 전환 비용의 버퍼를 트리거한다.
최적화 : 베 지어 UIBezierPath 무승부 프레임과 둥근 코어 그래픽
확장 UIView의 { /// BezierPath 배치 필릿 (: = _ UIRectCorner 코너 FUNC의 roundCorners .allCorners, RADIUS : CGFloat)을 { maskPath하자 = (UIBezierPath를 roundedRect : 경계, byRoundingCorners : 모서리, cornerRadii : CGSize (폭 : 반경 신장 반경)) 모양하자 = ) (CAShapeLayer를 shape.path = maskPath.cgPath layer.mask = 형상 } }
2. 다른 크기의 필렛
아이폰 OS 개발은 때때로 필렛을 설정해야 다른 크기의 요구가 발생할 수 있습니다, 당신은 특정 코드로 다음이다 달성하기 위해 경로를 그릴 필요
의 UIView는 {확장 // 둥근 네 가지 크기를 추가 {: (CornerRadii cornerRadii) FUNC의 addCorner을 경로하자 = createPathWithRoundedRect (:, cornerRadii을 self.bounds : 경계를 cornerRadii) 하자 shapLayer = CAShapeLayer () shapLayer.frame = self.bounds shapLayerpath = 의 경로 self.layer.mask = shapLayer } // 각 등심 크기의 구조체 CornerRadii { var에 좌상 : CGFloat = 0 VAR Topright : CGFloat = 0 var에 bottomleft : CGFloat = 0 VAR bottomRight : CGFloat = 0 } // 잘라 필렛 라인 함수로 꾸몄다 > - (CornerRadii : 다음 CGRect, cornerRadii 경계) FUNC createPathWithRoundedRect CGPath { 하게되어 minX = bounds.minX 하자 MINY = bounds.minY MAXX하자 = bounds.maxX을 MAXY하자 = bounds.maxY을 // 네 개의 원 얻을 송출 topLeftCenterX =되어 minX + cornerRadii.topLeft을 topLeftCenterY하자 = MINY + cornerRadii.topLeft을 topRightCenterX하자 = MAXX을 - cornerRadii.topRight을 topRightCenterY하자 = MINY + cornerRadii.topRight을 bottomLeftCenterX하자 =되어 minX + cornerRadii.bottomLeft을 bottomLeftCenterY하자 = MAXY을 - cornerRadii.bottomLeft을 bottomRightCenterX하자 = MAXX을 - cornerRadii.bottomRight을 bottomRightCenterY하자 = MAXY을 - cornerRadii.bottomRight을 // 시계 아이폰 OS 파라미터 UIView의 실제 시계 반대 방향으로, YES이지만 여기서 송출 경로 : CGMutablePath = CGMutablePath (); // 왼쪽 위 path.addArc (중앙 : CGPoint (X : topLeftCenterX, Y : topLeftCenterY) , RADIUS : cornerRadii.topLeft, startAngle로부터 : CGFloat.pi, endAngle * CGFloat.pi 3. / 2 시계 방향 : false로 ) // 오른쪽 상단 path.addArc (중앙 : CGPoint (X : topRightCenterX, Y : topRightCenterY) 반경 : cornerRadii.topRight, startAngle로부터 : * CGFloat.pi 3. / 2 , endAngle : 0 , 시계 방향으로 : false로 ) // 오른쪽 아래 path.addArc (중앙 : CGPoint (X : bottomRightCenterX, Y : bottomRightCenterY) 반경 : cornerRadii.bottomRight, startAngle로부터 : 0 , endAngle : CGFloat.pi / 2 , 시계 방향 : 거짓 ) // 底左 path.addArc (센터 : CGPoint (X : bottomLeftCenterX, Y : bottomLeftCenterY) 반경 : cornerRadii.bottomLeft, startAngle로부터 : CGFloat.pi / 2 , endAngle : CGFloat.pi 시계 방향 : 거짓 ) path.closeSubpath (); 반환 경로; } }