Ios 如何在avplayervewcontroller中添加“完成”按钮?
我使用的是avplayervewcontroller,无法显示Done按钮,也无法关闭播放器。也许你能帮我。这是我在objective-c中的代码Ios 如何在avplayervewcontroller中添加“完成”按钮?,ios,objective-c,avplayerviewcontroller,Ios,Objective C,Avplayerviewcontroller,我使用的是avplayervewcontroller,无法显示Done按钮,也无法关闭播放器。也许你能帮我。这是我在objective-c中的代码 UIView *view = self.view; NSURL *fileURL = [NSURL URLWithString: _detailData[0]]; AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init]; playe
UIView *view = self.view;
NSURL *fileURL = [NSURL URLWithString: _detailData[0]];
AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init];
playerViewController.player = [AVPlayer playerWithURL:fileURL];
self.avPlayerViewcontroller = playerViewController;
[self resizePlayerToViewSize];
[self dismissViewControllerAnimated:YES completion:nil];
[view addSubview:playerViewController.view];
[playerViewController.player play];
view.autoresizesSubviews = TRUE;
需要帮助的朋友们,非常感谢。谢谢你们的回答。我已经找到了:)
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self
action:@selector(aMethod:)
forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Done" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0); // set your own position
[view addSubview:button]; // or you can add [playerViewController.view addSubview:button];
-(void)aMethod:(UIButton *)button {
// Remove playerViewController.view
}
我们可以使用这个,并且“完成”按钮可以自动显示
NSURL *fileURL = [NSURL URLWithString: _detailData[0]];
// create an AVPlayer
AVPlayer *player = [AVPlayer playerWithURL:fileURL];
// create a player view controller
AVPlayerViewController *controller = [[AVPlayerViewController alloc]init];
controller.player = player;
[player play];
// show the view controller
[self addChildViewController:controller];
[self.view addSubview:controller.view];
controller.view.frame = self.view.frame;
创建新的UIButton并添加为视图的子视图您能在代码bro中解释更多吗?如果将按钮添加为playerViewController.view的子视图,它将始终可见(即使属性showsPlaybackControls设置为“否”),这在iOS 10.3.3中非常有效,但在iOS 11中不起作用。有什么想法吗?@DeepShah你的意思是“完成”按钮没有显示?尝试使用
bringSubviewToFront
或尝试在playervcontroller.view
上添加“完成”按钮。@Venkat Done按钮显示得很好,在iOS 10.3.3中工作得很好,但同样的代码在iOS 11中不起作用。按钮在iOS 11中显示,但单击事件不起作用。