self.wantsLayer = YES;self.layer.contents = [NSImage imagenamed:@"sprite-sheet"];self.layer.contentsGravity = kCAGravityleft;
当我运行它时,我得到了预期的视觉结果……以及以下日志崩溃:
** Misuse of NSImage and CALayer. contentsGravity is left. It should be one of resize,resizeAspect,or resizeAspectFill.
为什么?文档中没有迹象表明不应使用其他值.
解决方法 实际上,您看到的行为是在文档中.它只是在NSImage文档中,而不是CALayer文档(由我强调):Using Images with CALayer Objects总结Although you can assign an NSImage object directly to the
contents
property of a CALayer object,doing so may not always yIEld the best results. Instead of using your image object,you can use thelayerContentsForContentsScale:
method to obtain an object that you can use for your layer’s contents. That method creates an image that is suited for use as the contents of a layer and that is supports all of the layer’s gravity modes. By contrast,the NSImage class supports only thekCAGravityResize
,kCAGravityResizeAspect
,andkCAGravityResizeAspectFill
modes.
以上是内存溢出为你收集整理的macos – 为什么我在NSView中使用大多数contentGravity常量时会看到崩溃?全部内容,希望文章能够帮你解决macos – 为什么我在NSView中使用大多数contentGravity常量时会看到崩溃?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)