レイヤーホストNSViews(CALayerインスタンスを提供し、setLayer:
で設定したNSView)には明らかにサブビューが含まれています。なぜ明らかに?アップル独自のCocoa Slides sample code projectに、あなたはレイヤーホスティングであることに層担保されることからAssetCollectionView
を切り替えチェックボックスをチェックすることができますので:同じAssetCollectionView
クラスでレイヤーホスティングNSViewはサブビューを持つことができますか?
- (void)setUsesQuartzCompositionBackground:(BOOL)flag {
if (usesQuartzCompositionBackground != flag) {
usesQuartzCompositionBackground = flag;
/* We can display a Quartz Composition in a layer-backed view tree by
substituting our own QCCompositionLayer in place of the default automanaged
layer that AppKit would otherwise create for the view. Eventually, hosting of
QCViews in a layer-backed view subtree may be made more automatic, rendering
this unnecessary. To minimize visual glitches during the transition,
temporarily suspend window updates during the switch, and toggle layer-backed
view rendering temporarily off and back on again while we prepare and set the
layer.
*/
[[self window] disableScreenUpdatesUntilFlush];
[self setWantsLayer:NO];
if (usesQuartzCompositionBackground) {
QCCompositionLayer *qcLayer = [QCCompositionLayer compositionLayerWithFile:[[NSBundle mainBundle] pathForResource:@"Cells" ofType:@"qtz"]];
[self setLayer:qcLayer];
} else {
[self setLayer:nil]; // Discard the QCCompositionLayer we were using, and let AppKit automatically create self's backing layer instead.
}
[self setWantsLayer:YES];
}
}
を、サブビューが表示されるべき各画像のために追加されます。
- (AssetCollectionViewNode *)insertNodeForAssetAtIndex:(NSUInteger)index {
Asset *asset = [[[self assetCollection] assets] objectAtIndex:index];
AssetCollectionViewNode *node = [[AssetCollectionViewNode alloc] init];
[node setAsset:asset];
[[self animator] addSubview:[node rootView]];
[nodes addObject:node];
return [node autorelease];
}
私がアプリケーションをビルドして実行して、それを使いこなすと、すべてがうまくいくようです。
しかし、Apple's NSView Class Reference for the setWantsLayer:
methodにそれが読み取ります
あなたは 描画用のビューに依存すべきではない層ホスティングビューを使用して、またあなたは、レイヤのホスティングビューにサブビューを追加する必要があります。
本当ですか?サンプルコードが間違っていますか?それはうまくいくのですか?それともドキュメントが偽であるのですか?または、サブビューがアニメータープロキシを介して追加されているのでOKですか?
ありがとうとてもとても! –