【问题标题】:How to add touch gesture to Google VR iOS pod?如何向 Google VR iOS pod 添加触摸手势?
【发布时间】:2016-12-05 21:05:29
【问题描述】:
我正在使用 Google Cardboard VR pod 将虚拟现实添加到我的 iOS 应用程序中。我使用GVRPanoramaView 来显示 360 度全景照片。
在viewDidLoad() 中我启用了enableTouchTracking。但这仅在水平滑动时有效,您必须举起手机才能使其工作。
与嵌入网页的 Google VR 一样,您可以水平和垂直平移图像:https://developers.google.com/vr/concepts/vrview
iOS 中的 Google VR 也能做到这一点吗?就像上面的例子,在 Facebook 应用程序中嵌入 VR 有什么可能?
【问题讨论】:
标签:
ios
swift
virtual-reality
【解决方案1】:
iOS 中的 Google VR SDK 目前无法使用GVRPanoramaView、GVRCardboardView 或GVRVideoView 实现这一点,不幸的是,该库目前还不是开源的。
不过,Cardboard SDK 的开源端口也有一些尝试,例如:https://github.com/rsanchezsaez/CardboardSDK-iOS
可以修改 CBDSceneKit 示例以执行您想要的操作,如下所示:
- 删除
_cameraNode 属性。
- 将
UIPanGestureRecognizer 添加到视图控制器的视图中
- 在手势识别器的回调中,使用手势识别器上的
translationInView: 方法修改_cameraControlNode 的eulerAngles 属性。
类似:
- (void)didPan:(UIPanGestureRecognizer *)gestureRecognizer {
CGPoint translation = [gestureRecognizer translationInView:self.view];
_cameraControlNode.eulerAngles = SCNVector3Make(translation.y / 100.0, 0.0, translation.x / 100.0);
}
虽然我不是作者,但我不能对该库的整体可靠性做出任何承诺。我也不知道使用全景照片而不是 SceneKit 场景有多容易。