设置视图框架以匹配另一个不起作用的框架?

时间:2018-03-23 16:56:02

标签: ios swift uiview

我对这里发生的事感到非常困惑。我设置了一个视图来匹配另一个视图,因为它在后台播放我需要的音频:

     @IBOutlet weak var playerView: YouTubePlayerView!

override func viewDidLoad() {
      super.viewDidLoad()
    // plays in background but doesnt show video
    Djay.shared.youTubePlayer.frame = playerView.frame
    playerView = Djay.shared.youTubePlayer
// ... sets up player view like normal 
   playerView.delegate = self
    let playerVars = ["controls": "1", "playsinline": "1", "autohide": "1", "showinfo": "1", "autoplay": "1", "fs": "1", "rel": "0", "loop": "0", "enablejsapi": "1", "modestbranding": "1"]
    playerView.playerVars = playerVars as YouTubePlayerView.YouTubePlayerParameters
    playerView.loadVideoID("\(Djay.shared.songs[0].songId!)")
    NotificationCenter.default.addObserver(self, selector: #selector(appEnteredBackgound), name: Notification.Name.UIApplicationDidEnterBackground, object: nil)
    view.addSubview(activity)
    activity.center = playerView.center
    activity.hidesWhenStopped = true
    activity.activityIndicatorViewStyle = .gray
    activity.startAnimating()

上述代码的结果:

在背景和前景中播放视频的音频,但视频无处可见。然后,当玩家委托的videodidload方法被触发时,活动指示器旋转停止。然而,玩家不在视线中?

[![Pic of it not working][1]][1]

然而,当我删除这些行时:

     override func viewDidLoad() {
    super.viewDidLoad()
    // plays in background but doesnt show video
   // Djay.shared.youTubePlayer.frame = playerView.frame
  //  playerView = Djay.shared.youTubePlayer
    // ... sets up player view like normal

我在屏幕上播放视频,但音频无法在后台播放。

video playing

我的解决方案是我想像第一种情况一样设置视图(音频在后台播放正确)但我需要在屏幕上看到视频。

简而言之

为什么将框架设置为相同的Isnt工作?我该怎么做才能解决这个问题。

注意:youtubePlayerView是UIview的扩展。它内部有一个Web视图。如果您需要更多信息,请告诉我,我尽量做到尽可能简短。

0 个答案:

没有答案