是的,您可以集成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
我应该如何识别使用此代码按下哪个对象? –