自定义按钮在AVPlayer iOS 11中不起作用,但它在iOS 11下完美运行?

我知道这可能是一个重复的问题但是已经存在的问题没有解决方案所以,我再次要求可能开始赏金问题。

这是我在iOS 11下工作的代码:

AVPlayer *player = [AVPlayer playerWithURL:videoURL]; // create a player view controller avcontroller = [[AVPlayerViewController alloc]init]; avcontroller.player = player; [player play]; NSNotificationCenter *noteCenter = [NSNotificationCenter defaultCenter]; [noteCenter addObserverForName:AVPlayerItemDidPlayToEndTimeNotification object:nil queue:nil usingBlock:^(NSNotification *note) { NSLog(@"Video end"); self.avcontroller.player = nil; [self.avcontroller.view removeFromSuperview]; [self.view addSubview:delegate.tabViewControllerObj.tabBarController.view]; }]; _skip =[UIButton buttonWithType:UIButtonTypeCustom]; [_skip addTarget:self action:@selector(btnSkipTapped) forControlEvents:UIControlEventTouchUpInside]; [_skip setTitle:@"Skip" forState:UIControlStateNormal]; _skip.layer.borderWidth = 2.0f; _skip.layer.cornerRadius = 12; _skip.clipsToBounds = YES; _skip.layer.borderColor = [UIColor whiteColor].CGColor; // show the view controller [self addChildViewController:avcontroller]; [avcontroller.view addSubview:_skip]; [avcontroller.view bringSubviewToFront:_skip]; [self.view addSubview:avcontroller.view]; avcontroller.view.frame = self.view.frame; } -(void)viewDidLayoutSubviews{ [super viewDidLayoutSubviews]; _skip.frame = CGRectMake((self.view.frame.size.width-140),(self.view.frame.size.height-150),100.0,35.0); } 

这里是按钮点击function:

 - (IBAction)btnSkipTapped{ NSLog(@"Skip button clicked"); self.avcontroller.player = nil; [self.avcontroller.view removeFromSuperview]; [self.view addSubview:delegate.tabViewControllerObj.tabBarController.view]; } 

此代码将完美显示按钮,但按下按钮时,它不会调用btnSkipTapped函数。 任何帮助,将不胜感激 !

@DeepShah你已经在avcontroller.view添加了skip按钮,因此它的显示正常,但是你无法点击它,因为AVPlayerViewControllerContentView涵盖了那个跳过按钮。

见下图:

图片

所以你必须在self.view及其作品中添加跳过按钮。

 [self.view addSubview:_skip]; [self.view bringSubviewToFront:_skip];