【问题标题】:button on contentOverlayView not respondingcontentOverlayView 上的按钮没有响应
【发布时间】:2016-08-02 21:16:31
【问题描述】:

我无法解决这个问题 - 它应该很简单。

我有:

ShowAVPlayer 方法

AVPlayerItem *video = [[AVPlayerItem alloc] initWithURL:url];
AVQueuePlayer *queue = [[AVQueuePlayer alloc] initWithItems:@[video]];
video = [[AVPlayerItem alloc] initWithURL:url];   
[queue insertItem:video afterItem:nil];    
AVPlayer *player = [AVPlayer playerWithURL:url];
self.avmovieplayer = [AVPlayerViewController new];

我想在叠加层中添加一个按钮 - 但按钮没有响应:

UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setTitle:@"Do stuff" forState:UIControlStateNormal];
btn.frame = CGRectMake(0, 330, 320, 40);
[btn addTarget:self action:@selector(DoSpeech:) forControlEvents:UIControlEventTouchUpInside];
[btn setUserInteractionEnabled:true];
[self.avmovieplayer.contentOverlayView addSubview:btn];

这是我的DoSpeech,它永远不会被调用:

- (void) DoSpeech:(UIButton *)button {

   //DoSpeech

}

【问题讨论】:

  • 为什么要向 contentOverlayView 添加按钮?只需将其添加到查看。即 [self.avmovieplayer.view addSubview : btn];

标签: ios objective-c uibutton


【解决方案1】:

试试这个,

[btn setUserInteractionEnabled:YES];
[self.avmovieplayer.contentOverlayView bringSubviewToFront:btn];

希望它会有所帮助。

【讨论】:

  • 不幸的是没有 - 但无论如何感谢!当我点击 doStuff 按钮时,avplayerviewcontroller 正在响应该选项卡 - 可能是第一响应者吗
  • 好的,我从苹果文档中找到了答案:使用内容叠加视图在视频内容和控件之间添加额外的自定义视图。所以它看起来像这样:(在你的 UISlider 上有一堆其他层)要让它工作,只需改变这一行: [avPlayerViewController.contentOverlayView addSubview:sliderForVolumeControl];对此:[avPlayerViewController.view addSubview:sliderForVolumeControl]; - 查看更多信息:mzan.com/article/…
  • 同一个按钮
  • 很高兴听到@TheSnakeWizard 你已经解决了你的问题。干杯。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-06-24
  • 2017-12-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-17
相关资源
最近更新 更多