gpt4 book ai didi

objective-c - 无法让 [[id Animator] setAlphaValue : 0. 0] 工作

转载 作者:行者123 更新时间:2023-12-03 16:22:36 25 4
gpt4 key购买 nike

我正在尝试对 NSImageView 的不透明度淡出+帧大小变化进行动画处理。 FrameSize 工作顺利,但由于某种原因,alpha 值在动画开始时直接跳转到最终值。我已经尝试过对 super View 进行分层,但我已经没有想法了。这是我的代码示例 ->

AABLCLogo   -> NSImageView IBOutlet
speed -> 1.0f
<小时/>
//setting target frame for image view

NSRect newFrame = [AABLCLogo frame];
newFrame.origin.x = newFrame.origin.x + (newFrame.size.width*0.1);
newFrame.origin.y = newFrame.origin.y + (newFrame.size.height*0.1);
newFrame.size.width = newFrame.size.width * 0.8;
newFrame.size.height = newFrame.size.height * 0.8;

//backing layer for super view

[[AABLCLogo superview] setWantsLayer:YES];

//animating image view

[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration: speed];
[[AABLCLogo animator] setFrame: newFrame];
[[AABLCLogo animator] setAlphaValue: 0.0];
[NSAnimationContext endGrouping];

//XCode 4 delay snippet

double delayInSeconds = speed;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW,
delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime,
dispatch_get_main_queue(),
^(void) {

//code executes after ''speed'' seconds

[[AABLCLogo superview] setWantsLayer:NO];
[[self view] removeFromSuperview];

});

最佳答案

我怀疑这是主线程上的动画问题。在大多数情况下,如果您想同时为两件事设置动画,则需要使用 NSViewAnimation。使用此代码作为指导,它会调整窗口大小,同时淡出部分内容。

NSRect newWindowFrame = NSMakeRect(self.window.frame.origin.x, self.window.frame.origin.y, 640, self.window.frame.size.height);
NSMutableArray *viewAnimations = [NSMutableArray array];
NSDictionary *windowSizeDict = [NSDictionary dictionaryWithObjectsAndKeys:self.window, NSViewAnimationTargetKey, [NSValue valueWithRect:newWindowFrame], NSViewAnimationEndFrameKey, nil];
[viewAnimations addObject:windowSizeDict];

NSDictionary *animateOutDict = [NSDictionary dictionaryWithObjectsAndKeys:self.dataSidebarController.containerView, NSViewAnimationTargetKey, NSViewAnimationFadeOutEffect, NSViewAnimationEffectKey, nil];
[viewAnimations addObject:animateOutDict];

NSViewAnimation *animation = [[NSViewAnimation alloc] initWithViewAnimations:viewAnimations];
[animation setDuration:0.35];
[animation setAnimationBlockingMode:NSAnimationNonblocking];
[animation setDelegate:self];
[animation startAnimation];

关于objective-c - 无法让 [[id Animator] setAlphaValue : 0. 0] 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6335517/

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