在 Swift 中加载具有透明背景的 MPMoviePlayerViewController?

Loading MPMoviePlayerViewController with transparent background in Swift?

我在 Swift (iOS 8.1) 中使用 MPMoviePlayerViewController,并根据 How to play a local video with 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()
}