为什么 [imageView respondsToSelector: @selector (contentScaleFactor:)] 总是等于 NO?
我设置基本 sdk 4.1 和 ios 部署目标 = ios4.1。 contentScaleFactor 在 iOS 4.0 及更高版本中可用。
if ( [imageView respondsToSelector: @selector (contentScaleFactor:)] == YES )
{
imageView.contentScaleFactor = 1.0;
}
为什么我总是得到NO?
I set base sdk 4.1 and ios deployment target = ios4.1. The contentScaleFactor is available in iOS 4.0 and later.
if ( [imageView respondsToSelector: @selector (contentScaleFactor:)] == YES )
{
imageView.contentScaleFactor = 1.0;
}
Why do i always get NO ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它不会响应
contentScaleFactor:
,因为contentScaleFactor
是一个属性,具有以下访问器:没有其他名称为
contentScaleFactor
的方法接受单个参数(由:
标记)。因此,可用的选择器是
contentScaleFactor
和setContentScaleFactor:
。您可能正在寻找setContentScaleFactor:
,这就是 setter 的名称。将您的代码更改为:
It does not respond to
contentScaleFactor:
becausecontentScaleFactor
is a property, with the following accessors:There is no other method with the name
contentScaleFactor
that accepts a single parameter (marked by the:
).So, the selectors available are
contentScaleFactor
andsetContentScaleFactor:
. You are probably looking forsetContentScaleFactor:
, that's what the setter is called.Change your code to this:
因为选择器
contentScaleFactor:
与选择器contentScaleFactor
不同,并且都不对应于属性设置器的选择器,即setContentScaleFactor:
。您只需要执行以下操作:注意
:
已从选择器声明中消失。另请注意,将比例因子设置为1.0
将无法利用 Retina 显示屏。Because the selector
contentScaleFactor:
is different from the selectorcontentScaleFactor
, and neither corresponds to the property setter's selector, which issetContentScaleFactor:
. You just need to do this:Note the
:
is gone from the selector declaration. Also, note that setting your scale factor to1.0
will not take advantage of the Retina Display.