You can't control the compositing mode of views (or, really, CALayer
s) on iOS.
The best solution I can think of here is to leave both views with a clearColor
(or nil
) background, and use a single CAShapeLayer
to draw the background of both. If your two views have the same parent, it's not too hard.
Let's say the parent is of type ParentView
. Override layoutSubviews
in ParentView
to create and update the backdrop layer as necessary. Be sure to send setNeedsLayout
to the parent view if you move either of the child views.
ParentView.h
#import <UIKit/UIKit.h>
@interface ParentView : UIView
@property (nonatomic, strong) IBOutlet UIView *childView0;
@property (nonatomic, strong) IBOutlet UIView *childView1;
@end
ParentView.m
#import "ParentView.h"
@implementation ParentView {
CAShapeLayer *backdrop;
}
- (void)layoutSubviews {
[super layoutSubviews];
[self layoutBackdrop];
}
- (void)layoutBackdrop {
[self createBackdropIfNeeded];
[self arrangeBackdropBehindChildren];
[self setBackdropPath];
}
- (void)createBackdropIfNeeded {
if (backdrop == nil) {
backdrop = [CAShapeLayer layer];
backdrop.fillColor = [UIColor colorWithWhite:1 alpha:0.25].CGColor;
backdrop.fillRule = kCAFillRuleNonZero;
backdrop.strokeColor = nil;
}
}
- (void)arrangeBackdropBehindChildren {
[self.layer insertSublayer:backdrop atIndex:0];
}
- (void)setBackdropPath {
UIBezierPath *path = [UIBezierPath bezierPathWithRect:self.childView0.frame];
[path appendPath:[UIBezierPath bezierPathWithRect:self.childView1.frame]];
backdrop.path = path.CGPath;
}
@end