我有此代码,并且它完全按要求工作:

UIGraphicsBeginImageContext(self.bounds.size);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

但是,对于这一行:
[self.layer renderInContext:UIGraphicsGetCurrentContext()];

我收到警告(不是错误):

找不到'-renderInContext'方法。

如果实际上该方法有效,我怎么能收到此警告?如果仅将这一行注释掉,我的代码将失败;很明显,生产线和方法实际上是有效的。

最佳答案

您需要添加对CALayer-#import <QuartzCore/QuartzCore.h>的头文件的引用。您可能还需要将QuartzCore.framework添加到您的项目中。

10-08 11:48