ios – AVPlayer – UILabel在视频中不可见

前端之家收集整理的这篇文章主要介绍了ios – 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元素.如何让它去后台

解决方法

您可以使用视图图层的zPosition属性(它是CALayer对象)来更改视图的z-index.
theView.layer.zPosition = 1;

并在前面贴上标签

原文链接:https://www.f2er.com/iOS/333260.html

猜你在找的iOS相关文章