Я хочу добавить анимацию CATransition для NSView. У меня есть следующий код:
[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
Проблема в:
Я выполняю этот код.
Делаю
[[contentView animator] addSubview:mySubview];
в первый раз, не получается. Вид просто появляется. ВызываютсяCATransition
методы делегата, но флагfinished
НЕТ (ложь).Я удаляю представление по
[mySubview removeFromSuperview];
и оно удаляется с анимацией, флагfinished
= YES (true).Я повторяю шаги 2 и 3, и это работает с анимацией. Шаг 2 теперь сообщает, что анимация была
finished
(ДА). Работает как положено.
Что случилось?