CIFilter的CATransition第一次不能工作,第二次工作
我想为NSView添加CATransition动画。我有以下代码:
[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
标志为NO(false)。
我通过[mySubview removeFromSuperview];
删除视图并用动画删除,finished
flag= YES(true)。
我重复步骤2和3,它适用于动画。现在,步骤2告诉动画是finished
(是)。按预期工作。
怎么了?
没有找到相关结果
已邀请:
1 个回复
讼乐
,这必须在执行动画之前设置。更好的地方是
或
方法,或类似的东西。您需要在
上启用Core Animation,执行UI绘图(我的意思是允许您的应用执行此操作),然后才能执行动画。在我的情况下,我启用了Core Animation并立即执行动画,这就是为什么它对我不起作用。