ios - 如何在 AVPlayerViewController 中添加完成按钮?

标签 ios objective-c avplayerviewcontroller

我正在使用 AVPlayerViewController 并且无法显示 Done 按钮,也无法关闭播放器。也许你可以帮助我。这是我在 objective-c 中的代码

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
}

关于ios - 如何在 AVPlayerViewController 中添加完成按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36175842/

相关文章:

ios - 多用户 iOS SDK

ios - 为什么 Apple 向我发送消息说我的应用程序不支持 Ipv6?

iphone - 我怎样才能在iPhone中将一个类的值赋予另一个类?

ios - 视频无法使用 swift 代码

iphone - 由于 iphone 自动锁定导致应用程序崩溃?

objective-c - 在大型 Cocoa 应用程序中放置导出/操作的最佳位置?

objective-c - 如何检查对象是否为零

ios - AVPlayerViewController 确实退出了全屏

ios - AVPlayerViewController 是否自动带有 AVPlayer 对象?

ios - Swift 从滑动菜单中关闭邮件 Controller