Вы можете комбинировать формы обоих прямоугольников и создавать новый подуровень из окончательной формы. Этот слой будет действовать как ваш план.
Смотрите мой код, его полностью комментировал:
// Create shape of merged rectangles
UIBezierPath *outlinePath = [UIBezierPath bezierPathWithRect:subView1.frame];
[outlinePath appendPath:[UIBezierPath bezierPathWithRect:subView2.frame]];
// Configure the outline
UIColor *outlineColor = [UIColor redColor];
CGFloat outlineWidth = 1.0f * [[UIScreen mainScreen] scale];
// Create shape layer representing the outline shape
CAShapeLayer *outlineLayer = [CAShapeLayer layer];
outlineLayer.frame = mainView.bounds;
outlineLayer.fillColor = outlineColor.CGColor;
outlineLayer.strokeColor = outlineColor.CGColor;
outlineLayer.lineWidth = outlineWidth;
// Set the path to the layer
outlineLayer.path = outlinePath.CGPath;
// Add sublayer at index 0 - below everything already in the view
// so it looks like the border
// "outlineLayer" is in fact the shape of the combined rectangles
// outset by layer border
// Moving it at the bottom of layer hierarchy imitates the border
[mainView.layer insertSublayer:outlineLayer atIndex:0];
Выход выглядит следующим образом:
Edit: Я понял вопрос сначала. Ниже мой первоначальный ответ, который описывает пересечение прямых.
Вы можете просто создать другой вид, который будет представлять пересечение, и добавить его над двумя подзонами. Это рама будет пересечением subView1
и subView2
frame
s. Просто дайте ему ясный цвет фона и границы, используя его свойство layer
Ваш код может выглядеть следующим образом:
// Calculate intersection of 2 views
CGRect intersectionRect = CGRectIntersection(subView1.frame, subView2.frame);
// Create intersection view
UIView *intersectionView = [[UIView alloc] initWithFrame:intersectionRect];
[mainView addSubview:intersectionView];
// Configure intersection view (no background color, only border)
intersectionView.backgroundColor = [UIColor clearColor];
intersectionView.layer.borderColor = [UIColor redColor].CGColor;
intersectionView.layer.borderWidth = 1.0f;
нет анимированными в опции для этого АРХИВ. Я могу думать о нескольких способах вывести общий план. Например, вы можете добавить два вида под своими подзонами с прямоугольниками, расширяющими оригиналы, чтобы вы могли видеть контур. [http://whathaveyoutried.com] (http://whathaveyoutried.com) –