简体   繁体   English

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

[英]Loading MPMoviePlayerViewController with transparent background in Swift?

I am using the MPMoviePlayerViewController in Swift (iOS 8.1) and am using the code as per the answer at How to play a local video with Swift? 我在Swift(iOS 8.1)中使用MPMoviePlayerViewController,并根据如何使用Swift播放本地视频中的答案使用代码 ) and this all works fine. ),一切正常。

This code is as follows: 该代码如下:

    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)
    }

But am trying to make the background of the movie player transparent. 但是我正试图使电影播放器​​的背景透明。 I have found answers for using Objective-C but I am running into an error on compiling. 我已经找到了使用Objective-C的答案,但是在编译时遇到了错误。 The code I currently have is: 我目前拥有的代码是:

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

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

The compile error occurs on the subView.backgroundColor = UIColor.clearColor() line. 编译错误发生在subView.backgroundColor = UIColor.clearColor()行上。 The error is: 错误是:

'@lvalue $T4' is not identical to 'CGColor!!' '@lvalue $ T4'与'CGColor !!'不同

Any help as to what I am doing wrong here would be very much appreciated. 对于我在这里做错的任何帮助,将不胜感激。

I think you may want to specify that subView is of type UIView . 我认为您可能希望指定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