是的,您可以集成3D Touch和SpriteKit。
使用默認SpriteKit遊戲項目模板(SWIFT),設置您GameScene
是一個UIViewControllerPreviewingDelegate
和實施協議的方法,如:
public class GameScene: SKScene, UIViewControllerPreviewingDelegate {
public func previewingContext(previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
return UIViewController()
}
//Pop
public func previewingContext(previewingContext: UIViewControllerPreviewing, commitViewController viewControllerToCommit: UIViewController) {
return
}
}
在GameViewController.swift的viewDidLoad
,添加以下內容:
if let scene = GameScene(fileNamed:"GameScene") {
if self.traitCollection.forceTouchCapability == .Available {
registerForPreviewingWithDelegate(scene, sourceView: scene.view!)
}
}
在委託方法中,我返回一個空的視圖控制器。您可以創建一個類級別的變量,並通過適當的peek
-type視圖來實例化該VC。再一次,一個非常簡單的例子。如果您想從AppIcon交互中添加3D Touch,則需要修改Info.plist並從AppDelegate添加功能。 There is a good video on this topic。祝你好運!
你的男人。假期過後,我會試試這個。我會盡快發佈一些反饋。非常感謝。 – crashoverride777
我應該如何識別使用此代碼按下哪個對象? –