그래서 수학적으로 할 방법을 찾아 냈습니다! 기본적으로 기본 삼각법을 사용하여 교차점의 두 "호"에 필요한 각도를 찾고이 두 호로 구성된 베 지어 패스를 만듭니다. 그런 다음 베 지어 경로를 겹치면 완료됩니다! 만약 누군가가 관심이 있다면 내 코드는 다음과 같습니다 :)
참고 :이 두 원은 동일한 반지름을 가정하고 원형 같은 내 imageviews를 클리핑했습니다!
let circlePath = UIBezierPath()
let left_circle_center = left_image_view.center.x
let right_circle_center = right_image_view.center.x
let radius = left_image_view.frame.width/2
let angle = acos((left_circle_center - right_circle_center)/radius)
intersection_Path.addArc(withCenter: right_circle_center, radius: radius, startAngle: CGFloat(Double.pi-angle), endAngle: CGFloat(Double.pi+angle), clockwise: true)
intersection_Path.addArc(withCenter: left_circle_center, radius: radius, startAngle: CGFloat(-angle), endAngle: CGFloat(angle), clockwise: true
let intersection_area = CAShapeLayer()
intersection_area.path = intersection_Path.cgPath
intersection_area.borderColor = ...
intersection_area.strokeColor = ...
intersection_area.fillColor = ...
self.view.layer.addSublayer(intersection_area)
명확한 질문 : 방금 'UIImageViews'인 두 개의 UIViews 교차에 대해 이야기하고 있습니까? 또는 두 UIImageViews에 포함 된'UIImages'의 교차점? – dfd
이것은 이미지보기에서 임의의 이미지와 관련하여 복잡 할 수 있습니다 (이미지의 배경색이 흰색인지 투명인지, 이미 올바른 크기로 조정되었는지 여부 등 많은 질문을 함). 그러나 벤 다이어그램의 서클과 같은 두 개의 규칙적인 모양의 교차점을 찾고 있다면 계산이 매우 쉽습니다. – Rob
방금 ImageViews가 된 두 개의 UIView 였지만 형상을 사용하여 UIView를 수행하는 방법을 발견했습니다! – jasperthedog