繁体   English   中英

在Swift中使用透明背景加载MPMoviePlayerViewController吗?

[英]Loading MPMoviePlayerViewController with transparent background in Swift?

我在Swift(iOS 8.1)中使用MPMoviePlayerViewController,并根据如何使用Swift播放本地视频中的答案使用代码 ),一切正常。

该代码如下:

    let path = NSBundle.mainBundle().pathForResource("movie",     ofType:"m4v")
    let url = NSURL.fileURLWithPath(path!)
    moviePlayer = MPMoviePlayerController(contentURL: url)

    if let player = moviePlayer {
        player.view.frame = self.animationImage.frame
        player.backgroundView.backgroundColor = UIColor.clearColor()
        player.view.backgroundColor = UIColor.clearColor()

        for subView in player.view.subviews  {
            subView.backgroundColor = UIColor.clearColor()
        }

        player.prepareToPlay()
        player.scalingMode = .AspectFill
        player.controlStyle = .None
        self.view.addSubview(player.view)
    }

但是我正试图使电影播放器​​的背景透明。 我已经找到了使用Objective-C的答案,但是在编译时遇到了错误。 我目前拥有的代码是:

player.backgroundView.backgroundColor = UIColor.clearColor()
player.view.backgroundColor = UIColor.clearColor()

for subView in player.view.subviews  {
     subView.backgroundColor = UIColor.clearColor()
} 

编译错误发生在subView.backgroundColor = UIColor.clearColor()行上。 错误是:

'@lvalue $ T4'与'CGColor !!'不同

对于我在这里做错的任何帮助,将不胜感激。

我认为您可能希望指定subView为UIView类型。

for subView in moviePlayer!.view.subviews as [UIView] {
    subView.backgroundColor = UIColor.clearColor()
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM