3d Touch Not Available on iPhone 6s+

邮差的信 提交于 2019-12-10 17:45:51

问题


I am trying to add 3d touch into my application. I am trying to enable the user to use force touch on a UITableViewCell, like shown in this project. I am running this code:

if traitCollection.forceTouchCapability == UIForceTouchCapability.Available {
    registerForPreviewingWithDelegate(self, sourceView: view)
} else {
    print("unavailable")
}

I have tried running it on an iPhone 6s+, but I receive "unavailable" in my logs. Why can I not use 3d touch on a 3d touch-supported device? Thanks for your help.


回答1:


Just found some reference about 3D Touch APIs: according to the 3D Touch APIs documentation, Apple suggested that developers to read forceTouchCapability in traitCollectionDidChange: delegate method.

For example, you may check the value in your view controller using:

override func traitCollectionDidChange(previousTraitCollection: UITraitCollection?) {
    super.traitCollectionDidChange(previousTraitCollection)
    switch traitCollection.forceTouchCapability {
    case .Available:
        print("Available")
    case .Unavailable:
        print("Unavailable")
    case .Unknown:
        print("Unknown")
    }
}

Hope it helps.



来源:https://stackoverflow.com/questions/36811061/3d-touch-not-available-on-iphone-6s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!