1

我在 iPhone 6 和 6+ 设备上正确缩放图像时遇到问题。我正在开发自定义键盘扩展,并使用图像来呈现按键。

在正常模式下,所有设备上一切正常。在缩放模式下,我似乎需要添加更多的图像集,根据这个问题:Xcode 6 device-specific assets catalog。这很丑陋,但到目前为止它似乎工作得很好。

作为一个额外的头痛,我遇到了某些似乎以更低分辨率运行的应用程序。例如,LinkedIn 应用程序。即使是“缩放模式图片”也显得太大,溢出屏幕。它看起来以更接近 iPhone 5 的分辨率运行 - 960 像素 (320*3) 的图像在 6+ 设备上渲染效果还不错。

但是 - 当我记录 UIImageView 的宽度时,它在缩放模式和 LinkedIn 应用程序中都返回 375 点。UIScreen 的 scale 属性似乎也始终为 3。

这就是我记录的方式:

log.debug("Height: \(self.keyboardView.bounds.height)")
log.debug("Width: \(self.keyboardView.bounds.width)")
log.debug("Screen Width: \(UIScreen.mainScreen().bounds.width)")
log.debug("Screen scale: \(UIScreen.mainScreen().scale)")
log.debug("Screen native scale: \(UIScreen.mainScreen().nativeScale)")

这就是我得到的:

普通的

LinkedIn.app

Height: 216.0
Width: 375.0
Screen Width: 414.0
Screen scale: 3.0
Screen native scale: 2.60869565217391

MobileNotes.app

Height: 216.0
Width: 375.0
Screen Width: 414.0
Screen scale: 3.0
Screen native scale: 2.60869565217391

放大

移动笔记

Height: 216.0
Width: 375.0
Screen Width: 375.0
Screen scale: 3.0
Screen native scale: 2.88

领英

Height: 216.0
Width: 375.0
Screen Width: 375.0
Screen scale: 3.0
Screen native scale: 2.88

我是否还需要为这些旧应用程序提供一组额外的图像 - 如果需要,我如何检测到这样的应用程序当前正在运行?

4

1 回答 1

1

似乎检测到这一点的方法是

override func updateViewConstraints()

您可以在其中检查的值

self.view.frame.size.width

在旧版应用程序中将是 320。

于 2015-02-12T20:32:23.567 回答