【发布时间】:2015-03-23 05:12:26
【问题描述】:
我在 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!!'
对于我在这里做错的任何帮助将不胜感激。
【问题讨论】:
标签: ios swift uiview mpmovieplayercontroller