【问题标题】:AVPlayer - UILabel not visible over videoAVPlayer - UILabel 在视频中不可见
【发布时间】:2013-02-18 01:33:38
【问题描述】:
    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和avPlayerLayer的类型吗?

标签: ios objective-c avplayer


【解决方案1】:

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

 theView.layer.zPosition = 1;

并将标签放在前面

【讨论】:

  • 这让我发疯了 - 感谢您提供简单的解决方案!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多