Domanda

voglio aggiungere l'animazione CATransition per NSView. Ho il seguente codice:

[contentView setWantsLayer:YES];
NSRect rect = [contentView bounds];

NSData *shadingBitmapData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"restrictedshine" ofType:@"tiff"]]; // took from Apple's example
NSBitmapImageRep *shadingBitmap = [[[NSBitmapImageRep alloc] initWithData:shadingBitmapData] autorelease];
CIImage *inputShadingImage = [[[CIImage alloc] initWithBitmapImageRep:shadingBitmap] autorelease];
CIFilter *transitionFilter = [CIFilter filterWithName:@"CIRippleTransition"];
[transitionFilter setDefaults];
[transitionFilter setValue:[CIVector vectorWithX:NSMidX(rect) Y:NSMidY(rect)] forKey:@"inputCenter"];
[transitionFilter setValue:[CIVector vectorWithX:rect.origin.x Y:rect.origin.y Z:rect.size.width W:rect.size.height] forKey:@"inputExtent"];
[transitionFilter setValue:inputShadingImage forKey:@"inputShadingImage"];

CATransition *presentAnimation = [CATransition animation];
[presentAnimation setFilter:transitionFilter];
[presentAnimation setDuration:1.0];
[presentAnimation setDelegate:self];

[contentView setAnimations:[NSDictionary dictionaryWithObject:presentAnimation forKey:@"subviews"]];
// maybe there are memory leaks in this code, don't bother at this moment

Il problema è:

  1. eseguo questo codice.

  2. Lo faccio [[contentView animator] addSubview:mySubview]; per la prima volta, non funziona. appare appena vista. Metodi CATransition delegato sono chiamati, ma finished bandiera è NO (false).

  3. I Rimuovi Visualizza per [mySubview removeFromSuperview]; e rimuove con l'animazione, la bandiera finished = YES (true).

  4. I ripetere i punti 2 e 3 e funziona con l'animazione. Fase 2 ora dice che l'animazione era finished (SI). Funziona come previsto.

Che cosa c'è che non va?

È stato utile?

Soluzione

Problema risolto.

Prima di tutto: [contentView setWantsLayer:YES];, e questo deve essere impostata prima di eseguire animazioni. Posto migliore per questo sono awakeFromNib o init metodi o qualcosa di simile. È necessario attivare Core Animation in contentView, eseguire UI disegno (intendo permettere che la tua app per fare questo), e solo allora eseguire animazioni. Nel mio caso ho attivato Core Animation e Animazione eseguito immediatamente, ed è per questo che non ha funzionato per me.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top