如果此时尚未创建NSView,则CALayer转换不适用

时间:2015-11-23 10:37:35

标签: macos cocoa calayer nsview appkit

环境:OS X 10.11 SDK,XCode 7.2,Cocoa;

上下文:应该在创建视图时应用一些复杂的转换;

当我尝试以编程方式添加NSView时,如果将addSubview调用放在- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { NSView *view = [[NSView alloc] initWithFrame:NSMakeRect(100, 100, 100, 100)]; CALayer* newLayer = [CALayer layer]; newLayer.transform = CATransform3DMakeRotation(angle, 0.1f, 0.1f, 0.1f); [newLayer setBackgroundColor:[[NSColor greenColor] CGColor]]; [view setLayer:newLayer]; [view setWantsLayer:YES]; [_window.contentView addSubview:view]; } - (IBAction)click:(id)sender { angle += 0.1f; [[_window.contentView subviews] objectAtIndex:2].layer.transform = CATransform3DMakeRotation(angle, 0.1f, 0.1f, 0.1f); CATransform3D t = [[_window.contentView subviews] objectAtIndex:2].layer.transform; [[_window.contentView subviews] objectAtIndex:2].layer.edgeAntialiasingMask = !CATransform3DIsIdentity(t); } 之前,则忽略该属性:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    NSView *view = [[NSView alloc] initWithFrame:NSMakeRect(100, 100, 100, 100)];
    CALayer* newLayer = [CALayer layer];

    [newLayer setBackgroundColor:[[NSColor greenColor] CGColor]];

    [view setLayer:newLayer];
    [view setWantsLayer:YES];

    [_window.contentView addSubview:view];
    view.layer.transform = CATransform3DMakeRotation(angle, 0.1f, 0.1f, 0.1f);

} 

screenshot

如果我点击按钮,视图将按原样旋转。此外,在将视图添加到窗口后应用转换也可以:

Fatal Exception: java.lang.UnsatisfiedLinkError: Cannot load library: get_lib_extents[742]:   795 - /data/data/our.app/lib/libsomething.so is not a valid ELF object
       at java.lang.Runtime.loadLibrary(Runtime.java:370)
       at java.lang.System.loadLibrary(System.java:535)

我是否错过了一些要求或者只是误解了CALayer转换是如何工作的?

0 个答案:

没有答案