次のようにコードを書いたとき..
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetBlendMode(context, kCGBlendModeDifference);
sublayer = [CALayer layer];
sublayer.backgroundColor = [UIColor redColor].CGColor;
sublayer.opaque = NO;
sublayer.frame = CGRectMake(30, 30, 250, 200);
[sublayer renderInContext:context];
sublayer1 = [CALayer layer];
sublayer1.opaque = NO;
sublayer1.backgroundColor = [UIColor greenColor].CGColor;
sublayer1.frame = CGRectMake(120, 120, 100, 250);
[sublayer1 renderInContext:context];
}
次の最初の画像のようになりました
サブレイヤー、サブレイヤー1の位置は、フレームを設定しているため、正しい方法ではありません。それらの交点が混色です。実際の位置が設定されていないのはなぜですか?
しかし、私addSublayer
が使用すると、上の2番目の画像のようになりました。ここで、sublayer、sublayer1 の位置は正しい方法です。それらの交点は混色ではありません。何が起こったのですか?
サブレイヤーを作成した理由は、サブレイヤーをドラッグするときに、サブレイヤーの交差部分をブレンドカラーにする必要があるためです。誰か説明してください。
前もって感謝します。