如何将CALayer的内容设置为CGImageRef? [英] How do I set the contents of a CALayer to a CGImageRef?

查看:346
本文介绍了如何将CALayer的内容设置为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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆