我正在使用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 !!'
不同对于我在这里做错的任何帮助都将非常感激。
答案 0 :(得分:3)
我认为您可能希望指定subView的类型为UIView
。
for subView in moviePlayer!.view.subviews as [UIView] {
subView.backgroundColor = UIColor.clearColor()
}