I've got a layer with some complex drawing code in its -drawInContext: method. I'm trying to minimize the amount of drawing I need to do, so I'm using -setNeedsDisplayInRect: to update just the changed parts. This is working splendidly. However, when the graphics system updates my layer, it's transitioning from the old to the new image using a cross-fade. I'd like it to switch over instantly.
CATransaction を使用してアクションをオフにし、期間をゼロに設定しようとしましたが、どちらも機能しません。私が使用しているコードは次のとおりです。
[CATransaction begin];
[CATransaction setDisableActions: YES];
[self setNeedsDisplayInRect: rect];
[CATransaction commit];
代わりに使用すべき CATransaction の別の方法はありますか (kCATransactionDisableActions で -setValue:forKey: も試しましたが、結果は同じです)。
ベストアンサー1
これを行うには、レイヤーのアクション辞書を[NSNull null]
適切なキーのアニメーションとして返すように設定する必要があります。たとえば、次のようにします。
NSDictionary *newActions = @{
@"onOrderIn": [NSNull null],
@"onOrderOut": [NSNull null],
@"sublayers": [NSNull null],
@"contents": [NSNull null],
@"bounds": [NSNull null]
};
layer.actions = newActions;
レイヤーの 1 つ内でのサブレイヤーの挿入または変更、およびレイヤーのサイズと内容の変更時にフェードイン/フェードアウト アニメーションを無効にします。contents
更新された描画のクロスフェードを防ぐために、これが必要なキーだと思います。
Swift バージョン:
let newActions = [
"onOrderIn": NSNull(),
"onOrderOut": NSNull(),
"sublayers": NSNull(),
"contents": NSNull(),
"bounds": NSNull(),
]