2013-02-18 58 views
8
NSString *urlPath; 
    NSURL *videoUrl; 

    urlPath = [[NSBundle mainBundle] pathForResource:@"fogLoop" ofType:@"mp4"]; 
    videoUrl = [NSURL fileURLWithPath:urlPath]; 

    avPlayer = [AVPlayer playerWithURL:videoUrl]; 
    avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:avPlayer]; 

    avPlayerLayer.frame = videoView.layer.bounds; 

    avPlayerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; 

    [videoView.layer addSublayer: avPlayerLayer]; 

    avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone; 

    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(playerItemDidReachEnd:) 
               name:AVPlayerItemDidPlayToEndTimeNotification 
               object:[avPlayer currentItem]]; 

    [avPlayer play]; 

我在这个视图上有几个UILabel。我只是想将视频作为背景元素。有了这段代码,它似乎可以播放所有UI元素。我如何让它进入背景?AVPlayer - UILabel在视频中不可见

+0

你能解释avPlayer和avPlayerLayer的类型? – 2016-05-31 06:11:18

回答

7

您可以使用视图图层(它是CALayer对象)的zPosition属性来更改视图的z-index。

theView.layer.zPosition = 1; 

,并把标签前

+0

这让我疯狂 - 感谢您的简单解决方案! – 2017-04-08 22:05:59