iOS-VRView 探索

今天回家了,但總想寫點什么度過一下閑暇的時光。前晚看了蘋果發(fā)布會,覺得沒什么稀奇,幸運的是,在Facebook上看到直播一個小型開發(fā)會議(Swift Meetup),談論的是Google VR-SDK 的開發(fā)。

大東對 iOS-VR 的看法

水果目前并沒有開發(fā)支持VR的框架,而且像今年Oculus只支持三星產(chǎn)品,意味著它們開發(fā)的平臺iOS不能用呀。這不是很尷尬嗎。

Oculus powers the Samsung Gear VR, the most widely distributed VR headset in the world. Supported by Samsung’s global distribution and marketing efforts, Gear VR is compatible with the tens of millions of Samsung GALAXY flagship smartphones, including S7, S7 edge, S6, S6 edge, S6 edge +, and Note 5.

水果的開發(fā)者文檔里面也沒有一個框架是直接用來做VR的,只能通過Core-Motion來達到那種效果。但是自己開發(fā)又有點麻煩,可敬的Google開發(fā)團隊給iOS帶來Google-VRSDK,省去了很多麻煩。

或許水果會趁人意料地發(fā)布一款吊炸的VR設(shè)備讓你恨不得割腎也想買,或許只是開發(fā)一個框架來支持VR眼鏡。雖然我覺得兩者都會有??,讓我們拭目以待。

<a name="fenced-code-block">Let's Get Started It.</a>

Google VRView

所謂的Google VRView指的是能夠看全視角的影片或相片,實現(xiàn)相對比較簡單。目前國內(nèi)外也有很多類似的應用支持這個功能。

VR view allows you to embed 360 degree VR media into websites on desktop and mobile, and native apps on Android and iOS. This technology is designed to enable developers of traditional apps to enhance the apps with immersive content. For example, VR view makes it easy for a travel app to provide viewers with an underwater scuba diving tour as they plan a vacation or for a home builder to take prospective buyers on a virtual walkthrough before the home is built.

pod 'GVRSDK' //要用到cocoapods 講一個笑話:我是iOS開發(fā)者,我不知道cocoapods是什么.......

最好的學習方式還是看官方文檔。

看文檔發(fā)現(xiàn),Google VRView 的包含幾種類型:GVRCardboardView,GVRWidgetView(其中包含了兩個子類GVRPanoramaView,GVRVideoView)

<a name="fenced-code-block">GVRCardboardView</a> Defines a view responsible for rendering graphics in VR mode
<a name="fenced-code-block">GVRWidgetView </a> Defines a base class for all widget views, that encapsulates common functionality
<a name="fenced-code-block">GVRPanoramaView </a> Defines a view that can load and display 360-degree panoramic photos
<a name="fenced-code-block">GGVRVideoView </a> Defines a player view that renders a 360 video using OpenGL

GVRCardboardView 是用來開發(fā)某些自定義3D場景的,用到OpenGL,比較復雜,當然,SceneKit就可以結(jié)合它來進行開發(fā)的。
本次介紹的是GVRPanoramaView和GVRVideoView,先探索它們的使用。

要實現(xiàn)一個全景照片的View,可以直接使用GVRPanoramaView 類。

先看看繼承關(guān)系:
GVRPanoramaView Inherits(繼承) GVRWidgetView Inherits(繼承) UIView

  • step1:直接在storyboard拖拽一個UIView并連接到Controller中


    QQ20161029-0.png
@IBOutlet weak var panoView: GVRPanoramaView!
panoView.enableFullscreenButton = true
panoView.enableCardboardButton = true
panoView.enableTouchTracking = true
panoView.load(UIImage(named: "你的全景照片"), of: .stereoOverUnder)
Property 介紹
<GVRWidgetViewDelegate>delegate The delegate that is called when the widget view is loaded.
enableFullscreenButton 是否添加fullScreen 的按鈕
enableCardboardButton 是否添加 cardboard 的按鈕
enableTouchTracking 是否可以手勢拖動圖片
QQ20161029-3.png

就是圖片下方一欄的自定義功能

看文檔的時候發(fā)現(xiàn)還有一個 displayMode

displayMode: Controls the current GVRWidgetDisplayMode of the widget view.
Changing the value of this property is similar to pressing one of the fullscreen, cardboard or back UI buttons.

這個功能告訴你可以自定義按鍵實現(xiàn)一個全屏幕或者VR屏幕的轉(zhuǎn)換。這也讓自己能夠自定義界面布局。非常棒

接下來談談Delegate

panoView.delegate = self
extension VRViewController: GVRWidgetViewDelegate {
    func widgetViewDidTap(widgetView: GVRWidgetView!) {
        //Called when the user taps the widget view.
    }
    func widgetView(widgetView: GVRWidgetView!, didLoadContent content: AnyObject!) {
       //Called when the widget view's display mode changes.
    }
    func widgetView(widgetView: GVRWidgetView!, didChangeDisplayMode displayMode: GVRWidgetDisplayMode) {
        //Called when the content is successfully loaded. 
    }
    func widgetView(widgetView: GVRWidgetView!, didFailToLoadContent content: AnyObject!, withErrorMessage errorMessage: String!) {
        //Called when there is an error loading content in the widget view.
    }
}

假設(shè)我們希望在全景照片下通過點擊屏幕然后切換下一個照片,這里就可以通過調(diào)用widgetViewDidTap的方法來實現(xiàn)

func widgetViewDidTap(widgetView: GVRWidgetView!) {
        //或許你可以放在一個數(shù)組里面,進行循環(huán)切換
        panoView?.load(UIImage(named: "另一張照片"), of: GVRPanoramaImageType.mono)
    }

這里,GVRPanoramaImageType是要看你的圖片格式,如果你的圖片是一張相片形式的,就是mono,有的照片是同一張照片上下疊加形式的就是stereoOverUnder.

Screen Shot 2016-10-29 at 4.11.38 PM.png

前面提到 GVRWidgetDisplayMode它含一下幾種類型

Type 介紹
.embedded 就像上面示例圖一樣呈現(xiàn)在你自定義View中
.fullscreen 全屏幕形式展示
.fullscreenVR 有兩個顯示屏幕形式

假設(shè)一種情景是你在自己的自定義View中不想在點擊照片后切換圖片,這時候就可以用GVRWidgetDisplayMode來判斷.

當然還有展示全景形式的Video,這個跟全景照片類似,就不展示了。

強烈推薦Ray的一篇文章Introduction to Google Cardboard for iOS,里面對圖片和影片都有完整的介紹。也可以下載它們的Demo來試一試。

<a name="fenced-code-block">End</a>

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容