如何将CALayer的内容设置为CGImageRef? [英] How do I set the contents of a CALayer to a CGImageRef?
问题描述
我要将 CALayer
的内容设置为图片。 CALayer
有一个 contents
属性该属性的文档说,一个图层可以设置此属性一个CGImageRef显示图像作为其内容但是属性需要一个 id
所以在Xcode我得到以下问题:
I want to set the contents of a CALayer
to an image. The CALayer
has a contents
property The documentation on that property says that "a layer can set this property to a CGImageRef to display the image as its contents." But the property takes an id
so in Xcode I get the following issue:
语义问题:不兼容的指针
从
类型分配'id'类型CGImageRef'(aka'struct CGImage *')
Semantic Issue: Incompatible pointer types assigning to 'id' from 'CGImageRef' (aka 'struct CGImage *')
如何将 CGImageRef
分配给 c $ c>属性,当它只需要一个
id
?
推荐答案
显式地将 CGImageRef
c $ c> id 应修复警告。例如,
Explicitly casting CGImageRef
to id
should fix the warning. For example,
CGImageRef imageRef;
...
layer.contents = (id) imageRef;
应该正常工作。
这篇关于如何将CALayer的内容设置为CGImageRef?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!