gpt4 book ai didi

cocoa - 未调用核心动画委托(delegate)

转载 作者:行者123 更新时间:2023-12-03 16:33:59 26 4
gpt4 key购买 nike

我显然做错了什么。当我设置 View 框架时,我的委托(delegate)不会被调用。

框架版本不工作

-(void)someMethod {
CAAnimation *anim = [CABasicAnimation animation];
[anim setDelegate:self];
[[currentViewController view] setAnimations:[NSDictionary dictionaryWithObject:anim forKey:@"frame"]];
[[newViewController view] setAnimations:[NSDictionary dictionaryWithObject:anim forKey:@"frame"]];

[[[currentViewController view] animator] setFrame:currentTarget];
[[[newViewController view] animator] setFrame:newTarget];
}

- (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)flag {
NSLog(@"Yep; works!");
}

很奇怪;使用 alphaValue 的相同代码确实有效:

-(void)someMethod {
CAAnimation *anim = [CABasicAnimation animation];
[anim setDelegate:self];
[[currentViewController view] setAnimations:[NSDictionary dictionaryWithObject:anim forKey:@"alphaValue"]];
[[newViewController view] setAnimations:[NSDictionary dictionaryWithObject:anim forKey:@"alphaValue"]];

[[[currentViewController view] animator] setAlphaValue:0.5];
[[[newViewController view] animator] setAlphaValue:0.5];
}

- (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)flag {
NSLog(@"Yep; works!");
}

你能告诉我我在这里缺少什么吗?我只是不明白。感谢您抽出时间。

最佳答案

可以使用动画器来触发委托(delegate)方法来设置框架。为此,您需要分别为 frameSizeframeOrigin 键添加动画:

-(void)someMethod {
CAAnimation *anim = [CABasicAnimation animation];
[anim setDelegate:self];

[[currentViewController view] setAnimations:[NSDictionary dictionaryWithObject:anim forKey:@"frameOrigin"]];
[[currentViewController view] setAnimations:[NSDictionary dictionaryWithObject:anim forKey:@"frameSize"]];
[[newViewController view] setAnimations:[NSDictionary dictionaryWithObject:anim forKey:@"frameOrigin"]];
[[newViewController view] setAnimations:[NSDictionary dictionaryWithObject:anim forKey:@"frameSize"]];

[NSAnimationContext beginGrouping];
[[[currentViewController view] animator] setFrame:currentTarget];
[[[newViewController view] animator] setFrame:newTarget];
[NSAnimationContext endGrouping];
}

- (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)flag {
NSLog(@"Yep; works!");
}

在此示例中,您的委托(delegate)方法将为四个动画中的每一个动画触发。如果您要重新定位 View 而不调整大小,则不需要 frameSize 动画。

关于cocoa - 未调用核心动画委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3382129/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com