为什么 [imageView respondsToSelector: @selector (contentScaleFactor:)] 总是等于 NO?

发布于 2024-10-12 11:15:48 字数 248 浏览 2 评论 0原文

我设置基本 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

以为你会在 2024-10-19 11:15:48

它不会响应 contentScaleFactor:,因为 contentScaleFactor 是一个属性,具有以下访问器:

- (CGFloat)contentScaleFactor
- (void)setContentScaleFactor:(CGFloat)

没有其他名称为 contentScaleFactor 的方法接受单个参数(由 : 标记)。

因此,可用的选择器是 contentScaleFactorsetContentScaleFactor:。您可能正在寻找 setContentScaleFactor:,这就是 setter 的名称。

将您的代码更改为:

if ( [imageView respondsToSelector:@selector(setContentScaleFactor:)] == YES )
{
    // Or as bbum says, use [imageView setContentScaleFactor:1.0];
    imageView.contentScaleFactor = 1.0;
}

It does not respond to contentScaleFactor: because contentScaleFactor is a property, with the following accessors:

- (CGFloat)contentScaleFactor
- (void)setContentScaleFactor:(CGFloat)

There is no other method with the name contentScaleFactor that accepts a single parameter (marked by the :).

So, the selectors available are contentScaleFactor and setContentScaleFactor:. You are probably looking for setContentScaleFactor:, that's what the setter is called.

Change your code to this:

if ( [imageView respondsToSelector:@selector(setContentScaleFactor:)] == YES )
{
    // Or as bbum says, use [imageView setContentScaleFactor:1.0];
    imageView.contentScaleFactor = 1.0;
}
枫以 2024-10-19 11:15:48

因为选择器 contentScaleFactor: 与选择器 contentScaleFactor 不同,并且都不对应于属性设置器的选择器,即 setContentScaleFactor:。您只需要执行以下操作:

if ([imageView respondsToSelector: @selector(contentScaleFactor)])
{
    imageView.contentScaleFactor = 1.0;
}

注意 : 已从选择器声明中消失。另请注意,将比例因子设置为 1.0 将无法利用 Retina 显示屏。

Because the selector contentScaleFactor: is different from the selector contentScaleFactor, and neither corresponds to the property setter's selector, which is setContentScaleFactor:. You just need to do this:

if ([imageView respondsToSelector: @selector(contentScaleFactor)])
{
    imageView.contentScaleFactor = 1.0;
}

Note the : is gone from the selector declaration. Also, note that setting your scale factor to 1.0 will not take advantage of the Retina Display.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文