Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos viewDidLoad中的层备份NSView问题_Macos_Cocoa_Core Animation_Calayer_Nsview - Fatal编程技术网

Macos viewDidLoad中的层备份NSView问题

Macos viewDidLoad中的层备份NSView问题,macos,cocoa,core-animation,calayer,nsview,Macos,Cocoa,Core Animation,Calayer,Nsview,我开始变换一个图像视图。我最初的尝试是 self.imageView.wantsLayer = YES; self.imageView.layer.transform = CATransform3DMakeRotation(1,1,1,1); 不幸的是,我注意到转换只是偶尔发生(可能每5次运行一次)。在之间添加NSLog确认在某些运行中,self.imageView.layer为空。整个项目的状态如下图所示 这是一个非常简单的200x200 NSImageView,带有一个到生成的NSVie

我开始变换一个图像视图。我最初的尝试是

self.imageView.wantsLayer = YES;
self.imageView.layer.transform = CATransform3DMakeRotation(1,1,1,1);
不幸的是,我注意到转换只是偶尔发生(可能每5次运行一次)。在之间添加NSLog确认在某些运行中,
self.imageView.layer
为空。整个项目的状态如下图所示

这是一个非常简单的200x200 NSImageView,带有一个到生成的NSViewController的出口。一些实验表明,设置wantsDisplay并不能解决这个问题,但将转换放在NSTimer上可以使它每次都工作。我想解释一下为什么会发生这种情况(我想这是由于某些比赛条件)

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

更新

删除
wantsLayer
并在Interface Builder中疯狂启用核心动画层并没有解决该问题

也没有尝试将其动画化(我不确定我希望得到什么)


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

将转换代码移动到
viewDidAppear
使其每次都能工作

- (void)viewDidAppear {
    [super viewDidAppear];
    self.imageView.animator.layer.transform = CATransform3DMakeRotation(1,1,1,1);
}
// 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];
- (void)viewDidAppear {
    [super viewDidAppear];
    self.imageView.animator.layer.transform = CATransform3DMakeRotation(1,1,1,1);
}