लेयर-होस्टिंग एनएसवीव्स (इसलिए NSViews कि आप CALayer इंस्टेंस की आपूर्ति करते हैं और setLayer:
के साथ सेट करते हैं) में स्पष्ट रूप से सबव्यूव शामिल हो सकते हैं। जाहिर है क्यों? क्योंकि एप्पल के स्वयं के Cocoa Slides sample code project में, आप एक चेकबॉक्स है कि परत मेजबानी होने के परत समर्थित होने से AssetCollectionView
स्विच जांच कर सकते हैं:क्या परत-होस्टिंग NSViews को सबव्यूज़ रखने की अनुमति है?
- (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];
}
}
ही AssetCollectionView
कक्षा में, subviews वह प्रत्येक छवि प्रदर्शित किया जाना चाहिए के लिए जोड़ रहे हैं:
- (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 में इसे पढ़ता है:
जब एक परत-होस्टिंग दृश्य आपको ड्राइंग के लिए दृष्टिकोण पर निर्भर नहीं होना चाहिए का उपयोग कर, और न ही आप परत-होस्टिंग देखने के लिए subviews जोड़ने चाहिए।
सत्य क्या है? क्या नमूना कोड गलत है और यह सिर्फ एक संयोग है कि यह काम करता है? या दस्तावेज झूठा है (जो मुझे शक है)? या यह ठीक है क्योंकि उपन्यास एनिमेटर प्रॉक्सी के माध्यम से जोड़े गए हैं?
धन्यवाद बहुत बहुत! –