AVPlayer - UILabel在视频中不可见 [英] AVPlayer - UILabel not visible over video

查看:124
本文介绍了AVPlayer - UILabel在视频中不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    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元素。如何让它转到后台?

I have several UILabels on this view. I just want the video as a background element really. With this code, it seems to play over all the UI elements. How do I make it go to the background?

推荐答案

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

You can use the zPosition property of the view's layer (it's a CALayer object) to change the z-index of the view.

 theView.layer.zPosition = 1;

并将标签带到前面

这篇关于AVPlayer - UILabel在视频中不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆