检查是否支持UIGraphicsBeginImageContextWithOptions [英] Checking if UIGraphicsBeginImageContextWithOptions is supported

查看:126
本文介绍了检查是否支持UIGraphicsBeginImageContextWithOptions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iOS应用程式。它目前只适用于iOS 4,因为我在几个场合使用以下方法:UIGraphicsBeginImageContextWithOptions。这个方法只适用于iOS 4,因此我的应用程序当前崩溃/不工作在iPhone OS 3.除了这种方法,没有理由应用程序不应该在iPhone OS 3上工作。如何进行检查看到wether还是不是这种方法可用?我尝试下面没有成功:

I'm working on an iOS app. It currently only works on iOS 4 since I use the following method on several occasions: "UIGraphicsBeginImageContextWithOptions". This method is only available in iOS 4 and therefor my app currently crashes/doesn't work on iPhone OS 3. Aside from this method there is no reason why the app should not work on iPhone OS 3. How do I make a check to see wether or not this method is available ? I've tried the following without succes:

if([self respondsToSelector:@selector(UIGraphicsBeginImageContextWithOptions)]) {
    UIGraphicsBeginImageContextWithOptions(targetSize, NO, 0.0); // this will crop
}
else 
{
    UIGraphicsBeginImageContext(targetSize);

}



我只尝试过这样的变体:

I've only tried variations like this:

if([self respondsToSelector:@selector(UIGraphicsBeginImageContextWithOptions:size:opaque:scale:)])

if([self respondsToSelector:@selector(UIGraphicsBeginImageContextWithOptions:)])

任何帮助将不胜感激。

推荐答案

UIGraphicsBeginImageContextWithOptions是一个C函数,因此您不能使用Objective- c $ c> -respondsToSelector:来测试它的存在。

UIGraphicsBeginImageContextWithOptions is a C function, so you can't use Objective-C methods like -respondsToSelector: to test its existence.

然而,你可以

You could, however, weak link the UIKit framework, and then check if UIGraphicsBeginImageContextWithOptions is NULL:

if (UIGraphicsBeginImageContextWithOptions != NULL) {
   UIGraphicsBeginImageContextWithOptions(...);
} else {
   UIGraphicsBeginImageContext(...);
}

这篇关于检查是否支持UIGraphicsBeginImageContextWithOptions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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