objectiveccoder001
objectiveccoder001

Reputation: 3031

AVPlayer - UILabel not visible over video

    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?

Upvotes: 8

Views: 2353

Answers (1)

Shashank Kulshrestha
Shashank Kulshrestha

Reputation: 1556

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

Upvotes: 7

Related Questions