嵌入YouTube视频时出现自动布局问题

时间:2016-08-23 07:46:31

标签: ios youtube swift2 ios-autolayout

我在嵌入YouTube视频时遇到了自动布局问题。事实上,Apple刚刚拒绝了我以这些理由发送的应用程序。这是我提交的代码。

import UIKit

 class ImproveViewController: UIViewController {

@IBOutlet weak var videoView: UIWebView!

override func viewDidLoad() {
    super.viewDidLoad()
    let youTubeUrl = "https://www.youtube.com/embed/NpepI1dtIz8"
    videoView.allowsInlineMediaPlayback = true

    dispatch_async(dispatch_get_main_queue(), { () -> Void in


        self.videoView.loadHTMLString("<iframe width=\"\(self.videoView.frame.width)\" height=\"\(self.videoView.frame.height)\" src=\"\(youTubeUrl)\" frameborder=\"0\" allowfullscreen></iframe>", baseURL: nil)

        print("This is run on the main queue, after the previous code in outer block")
    })

    // Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
}
*/

}

这是我在模拟器中运行时的样子。enter image description here

如何解决这个问题?任何帮助将不胜感激。我已将Web视图约束添加到整个屏幕。再次感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

您的代码看起来没问题,我已经测试过了。我认为你在约束方面有问题。

只需将constants = 0的Top,Bottom,Leading和trailing约束添加到superview