迅速。显示透明背景的视频

时间:2016-09-17 19:58:16

标签: swift transparency mpmovieplayer

我的主视图有一些不同的类别,当玩家完成100%的类别时,我想要五彩纸屑下雨。

我将五彩纸屑视为视频(只有五彩纸屑可见,背景是透明的)我试图用MPMoviePlayer在我的视图上显示视频,如下所示:

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

if let player = self.moviePlayer {
    player.view.frame = CGRect(x: 0, y: 0, width: self.view.bounds.height * 1.2 * (1920/1080), height: self.view.bounds.height * 1.2)
    player.view.frame.origin.x = 0 - (player.view.frame.width - self.view.bounds.width) / 2
    player.backgroundView.backgroundColor = UIColor.clearColor()
    player.view.backgroundColor = UIColor.clearColor()

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

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

但它不起作用,这就是显示:

MPMoviePlayer

如何使其发挥作用,或者还有其他方法可以做到这一点?

0 个答案:

没有答案