Skip to content

Commit

Permalink
Merge pull request #5 from bbethke/feature/video-positioning
Browse files Browse the repository at this point in the history
Resolve a few issues with videos and slides positioning off screen
  • Loading branch information
BalestraPatrick committed May 10, 2016
2 parents beebf7e + cc2030e commit a9aa7e3
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions RealmVideo/RealmVideoViewController.swift
Expand Up @@ -66,10 +66,13 @@ class RealmVideoViewController: UIViewController, UIWebViewDelegate {

/// Called when the AVPlayer is started in the UIWebView
func playerDidStart() {
let window = UIApplication.sharedApplication().windows.last!
window.rootViewController!.view.addSubview(floatingSlides)
window.rootViewController?.view.bringSubviewToFront(floatingSlides)
// Ensure we have a window, rootViewController, and that we're not adding a duplicate floating slide view
guard let window = UIApplication.sharedApplication().windows.last,
let rootViewController = window.rootViewController where
rootViewController.view.subviews.contains(floatingSlides) == false else { return }

rootViewController.view.addSubview(floatingSlides)
rootViewController.view.bringSubviewToFront(floatingSlides)
}

/// Update slides position
Expand Down Expand Up @@ -147,20 +150,18 @@ class RealmVideoViewController: UIViewController, UIWebViewDelegate {

// Get position of the video and slides from the UIWebView
func webViewDidFinishLoad(webView: UIWebView) {
if positionOfSlides == nil {
let position = positionOfElementWithId("slideshow-player") + 91.0
if position > 91.0 {
positionOfSlides = position
}
if positionOfSlides == nil && !webView.loading {
let position = positionOfElementWithId("slideshow-player")
positionOfSlides = position
}

if positionOfVideo == nil {
let position = positionOfElementWithId("preroll-overlay") + 63
if position > 63.0 {
positionOfVideo = position
} else if position == 63.0 {
let youtubePosition = positionOfElementWithId("video-player") + 63
if positionOfVideo == nil && !webView.loading {
let position = positionOfElementWithId("preroll-overlay")
if position == 0.0 {
let youtubePosition = positionOfElementWithId("video-player")
positionOfVideo = youtubePosition
} else {
positionOfVideo = position
}
}
}
Expand All @@ -174,4 +175,3 @@ class RealmVideoViewController: UIViewController, UIWebViewDelegate {
presentViewController(alert, animated: true, completion: nil)
}
}

0 comments on commit a9aa7e3

Please sign in to comment.