Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
自定义按钮不适用于AVPlayer iOS 11,但它';它在iOS 11下工作得很好?_Ios_Objective C_Avplayer_Ios11_Avplayerviewcontroller - Fatal编程技术网

自定义按钮不适用于AVPlayer iOS 11,但它';它在iOS 11下工作得很好?

自定义按钮不适用于AVPlayer iOS 11,但它';它在iOS 11下工作得很好?,ios,objective-c,avplayer,ios11,avplayerviewcontroller,Ios,Objective C,Avplayer,Ios11,Avplayerviewcontroller,我知道这可能是一个重复的问题,但已经存在的问题没有解决方案,所以,我再次要求可能开始赏金问题 以下是我在iOS 11下运行的代码: AVPlayer *player = [AVPlayer playerWithURL:videoURL]; // create a player view controller avcontroller = [[AVPlayerViewController alloc]init]; avcontroller.player = player; [player pla

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

以下是我在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);
}
这里是按钮点击功能:

- (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
中添加了跳过按钮,因此其显示正确,但您无法单击它,因为
avplayervcontrollercontentview
覆盖了该跳过按钮

见下图:

因此,您必须在
self.view
及其作品中添加跳过按钮

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

我也面临同样的问题。在我的例子中,我展示了AvPlayServiceWController并添加了一个自定义按钮。AvPlayServiceWController上显示了一个按钮,但无法触发按钮操作。我尝试了您上面提到的操作,但没有成功。此问题仅在iOS 11中出现。让btn=UIButton(类型:。自定义)作为UIButton self.playerViewController.view?.addSubview(btn)self.playerViewController.view?.bringSubview(toFront:self.castWrapperView)self.present(self.playerViewController,动画:false,完成:nil)@Nirav对这件事有什么想法吗?添加到
self.view
self.playerwcontroller.view
?尝试添加
self.view
self.view?.addSubview(btn)self.view?.bringSubview(toFront:btn)按钮现在没有显示在播放器视图上,你能给我代码吗?所以我可以检查一下。在dropbox或anywhere代码链接中。如果可能的话