I need to add a custom button to the AVPlayerViewController, which will be displayed in both full screen and not full screen for an application with iOS 8.
Adding a button to AVPlayerViewController.view or containing a view will work for non-full-screen mode, but when the player switches to full-screen mode, the button will no longer be visible. I found that if I add a button to AVPlayerViewController.ContentOverlayView, it will appear in full-screen and not full-screen modes, but then it will not be visible that ContentOverlayView is responding to any clicks, so the button cannot be pressed. Does anyone know of another place to add a button or a way to make ContentOverlayView respond to touches?
Code example
AVPlayerViewController *playerView = [[AVPlayerViewController alloc] init];
playerView.player = [AVPlayer playerWithURL:movieURL];
CGRect viewInsetRect = CGRectInset ([self.view bounds],
kMovieViewOffsetX,
kMovieViewOffsetY );
[[playerView view] setFrame:viewInsetRect];
[self.view addSubview: [playerView view]];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.backgroundColor = [UIColor yellowColor];
btn.frame = CGRectMake(50, 50, 200, 75);
[btn addTarget:self action:@selector(didSelectButton:) forControlEvents:UIControlEventTouchUpInside];
[btn setUserInteractionEnabled:YES];
[btn setEnabled:YES];
[playerView.contentOverlayView addSubview:btn];
source
share