gpt4 book ai didi

macos - viewDidLoad 中层支持的 NSView 问题

转载 作者:行者123 更新时间:2023-12-03 17:19:31 26 4
gpt4 key购买 nike

我开始改造 NSImageView。我最初的尝试是

self.imageView.wantsLayer = YES;
self.imageView.layer.transform = CATransform3DMakeRotation(1,1,1,1);

不幸的是,我注意到转换仅有时发生(可能每 5 次运行一次)。在之间添加 NSLog 确认在某些运行中 self.imageView.layer 为 null。整个项目的状态如下图所示。

Project state

这是一个极其简单的 200x200 NSImageView,带有生成的 NSViewController 的导出。一些实验表明设置 WantsDisplay 并不能解决问题,但是将转换放在 NSTimer 上可以使其每次都能工作。我希望解释为什么会发生这种情况(我认为这是由于某些竞争条件造成的)。

我在 macOS 10.12 上使用 Xcode 8,但我怀疑这是问题的原因。

更新

删除 wantsLayer 并在 Interface Builder 中疯狂启用核心动画层并不能解决问题。

Ticked core animation layers

也没有尝试将其动画化(我不确定我想要什么)

// Sometimes works.. doesn't animate
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) {
context.duration = 1;
self.imageView.animator.layer.transform = CATransform3DMakeRotation(1,1,1,1);
} completionHandler:^{
NSLog(@"Done");
}];

// Animates but only sometimes
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(1,1,1,1)];
animation.duration = 1;
[self.imageView.layer addAnimation:animation forKey:nil];

最佳答案

在尝试 allowedImplicitAnimation 之后,我意识到我可能太早尝试制作动画了。

将转换代码移至 viewDidAppear 使其每次都能正常工作。

- (void)viewDidAppear {
[super viewDidAppear];
self.imageView.animator.layer.transform = CATransform3DMakeRotation(1,1,1,1);
}

关于macos - viewDidLoad 中层支持的 NSView 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38555940/

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