AVPlayer - UILabel not visible over video

本秂侑毒 提交于 2019-12-22 04:42:49

问题


    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];

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?


回答1:


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;

And Bring labels to front



来源:https://stackoverflow.com/questions/14928243/avplayer-uilabel-not-visible-over-video

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!