小编Les*_*ary的帖子

如何在所有可用的iPhone分辨率上处理图像比例?

如果我们想要使用此图像覆盖所有分辨率的屏幕的全宽和半高,那么最适合图像的尺寸是:background.png,background @ 2x.png和background@3x.png iPhone肖像应用?

这就是我们现在拥有的:

Device          Points    Pixels     Scale  Physical Pixels   Physical PPI  Size
iPhone X        812x375   2436x1125  3x     2436x1125         458           5.8"
iPhone 6 Plus   736x414   2208x1242  3x     1920x1080         401           5.5"
iPhone 6        667x375   1334x750   2x     1334x750          326           4.7"
iPhone 5        568x320   1136x640   2x     1136x640          326           4.0"
iPhone 4        480x320   960x640    2x     960x640           326           3.5"
iPhone 3GS      480x320   480x320    1x     480x320           163           3.5"
Run Code Online (Sandbox Code Playgroud)

iPhone分辨率

有人说,对于iPhone 6 Plus,对于边缘到边缘的图像(如屏幕左下边缘的横幅),他们会准备back@3x.png,宽度为1242,iPhone 6为back@2x.png,宽度750以匹配iPhone 6的屏幕尺寸,但我不认为这是一个好主意,因为1242/3 = 414和750/2 = 375所以将它们命名为@ 2x和@ 3x没有意义.然后应该有什么宽度back.png - 375或414?

图形名称使用@ 2x和@ 3x后缀,因此如果例如image@3x.png具有30x30分辨率,则逻辑上认为image@2x.png应具有20x20分辨率,image.png应为10x10.这意味着如果我们想要为每个屏幕设置清晰的全宽图像,那么我们可能应该创建back@3x.png,宽度为414*3 = …

iphone screen-resolution ios iphone-6 iphone-6-plus

98
推荐指数
3
解决办法
8万
查看次数

在 didSet 之后,观察 Swift 中 @Published var 的变化吗?

假设我们有以下用 Swift 编写的使用合并的代码:

import UIKit
import Combine

class Test {
  @Published var array: [Int] = [] {
    willSet {
      print("willSet \(newValue.count)")
    }
    didSet {
      print("didSet \(array.count)")
    }
  }
}

var test = Test()
var subscriber = test.$array.sink { values in
  print("arrayCount: \(test.array.count) valuesCount: \(values.count)")
}

print("1 arrayCount \(test.array.count)")
test.array = [1, 2, 3]
print("2 arrayCount \(test.array.count)")
test.array = [1]
print("3 arrayCount \(test.array.count)")
Run Code Online (Sandbox Code Playgroud)

此代码在控制台上打印以下结果(可以在 Playground 中快速测试):

arrayCount: 0 valuesCount: 0
1 arrayCount 0
willSet 3
arrayCount: 0 valuesCount: 3
didSet 3 …
Run Code Online (Sandbox Code Playgroud)

ios swift combine

7
推荐指数
3
解决办法
6366
查看次数

如何在tvOS中打开GameCenter

如何在tvOS中打开游戏中心排行榜?我已将此代码用于我的iPhone游戏,tvOS上没有"leaderboardIdentifier".

我计划在AppleTV上使用相同的排行榜(这将是同一个游戏).

非常感谢你的帮助,Stefan

    @IBAction func handleGameCenter(sender: UIButton) {
        let gcViewController = GKGameCenterViewController()
        gcViewController.viewState = GKGameCenterViewControllerState.Leaderboards
        gcViewController.leaderboardIdentifier = gamePrefix + "Leaderboard"
        gcViewController.gameCenterDelegate = self

        // Show leaderboard
        self.presentViewController(gcViewController, animated: true, completion: nil)
    }

    func gameCenterViewControllerDidFinish(gameCenterViewController: GKGameCenterViewController) {
        gameCenterViewController.dismissViewControllerAnimated(true, completion: nil)
    }
Run Code Online (Sandbox Code Playgroud)

game-center apple-tv game-center-leaderboard tvos

6
推荐指数
1
解决办法
2211
查看次数

iOS 上的 BLE 广告和 CBAdvertisementDataLocalNameKey 大小

在 iOS 上使用蓝牙低能耗广告时,作为 CBAdvertisementDataLocalNameKey 广告的数据的最大大小是多少?在进行一些测试时,我使用以下代码进行 BLE 广告:

var manager: CBPeripheralManager!
//...
let customData = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
manager.startAdvertising([CBAdvertisementDataServiceUUIDsKey:[serviceCBUUID], CBAdvertisementDataLocalNameKey: customData])
Run Code Online (Sandbox Code Playgroud)

我注意到,在检测到外设 ( func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber)) 时调用的委托方法中的第二个设备上,我的自定义数据被剪切为以下字符串:“01234567”,因此它只有 8 个字节。startAdvertising 函数的文档提到“对于支持的广告数据键的任意组合,初始广告数据中最多有 28 个字节的空间”。有人能解释一下为什么在我的例子中它只有 8 个字节吗?实际上,iOS 上的 CBAdvertisementDataLocalNameKey 总是 8 个字节,还是这个数字可以更改?如何计算广告数据包中将成功发送的字节数(在我的例子中为 8 字节)?在 iOS 上使用 BLE 时,有什么办法可以通告超过 8 个字节吗?同时宣传的服务数量有限制吗?例如,是否可以同时通告 10 个不同的 uuid,每个 uuid 各有 8 个字节,总共允许同时通告 80 个字节?

ios core-bluetooth bluetooth-lowenergy

2
推荐指数
1
解决办法
2036
查看次数