如何在播放视频的AVPlayer上放置标签?

时间:2018-11-25 02:27:27

标签: ios objective-c

如何在播放视频的AVPlayer上方或上方放置标签?我曾尝试按照另一篇SO帖子中的建议调整Z位置,但是它不起作用,视频播放器似乎位于所有标签的前面。

    //this is my label

    self.commentLabel.layer.masksToBounds = YES;
    self.commentLabel.layer.cornerRadius = 15.0;
    [self.commentLabel sizeToFit];
    self.commentLabel.center = CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/1.4);
    self.commentLabel.layer.zPosition=100;

    //this is my video player

    self.playerViewController = [[AVPlayerViewController alloc] init];
    NSString*str3=[self.FRIENDDATA stringByReplacingOccurrencesOfString:@" " withString:@"_"];
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://my.website.com/%@/%@.mp4", str3,self.RANDOMDATA]];
    AVURLAsset *asset = [AVURLAsset assetWithURL: url];
    AVPlayerItem *item = [AVPlayerItem playerItemWithAsset: asset];
    AVPlayer * player = [[AVPlayer alloc] initWithPlayerItem: item];
    self.playerViewController.player = player;
    [self.playerViewController.view setFrame:self.referenceImageView.frame];
    self.playerViewController.view.layer.zPosition=0;
    self.playerViewController.showsPlaybackControls = YES;
    [self.view addSubview:self.playerViewController.view];

1 个答案:

答案 0 :(得分:-1)

您是否尝试过将标签子视图添加到playerViewController上?

[self.playerViewController.view addSubview:self.commentLabel];

从代码中,我不确定commentLabel尚未初始化,还是在代码中的其他地方或从情节提要中初始化。在commentLabel上初始化playerViewController

赞:

UILabel *commentLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/1.4, 100, 100)];

[self.playerViewController.view addSubview:commentLabel];

那应该可以解决您的问题