MPMoviePlayer 完成按钮问题
我正在使用 MPMoviePlayer 来显示视频。我进入全屏模式,当单击“完成”按钮时,我希望它从我的视图中删除整个电影播放器。目前它仅退出全屏模式。你如何跟踪被点击的doneButton或者我该如何解决这个问题?
I am using a MPMoviePlayer to display a video. I go into full screen and when the done button is clicked I want it to remove of the entire movie player from my view. Currently it only goes out of the fullscreen mode. How do you track the doneButton being clicked or just how do I go about fixing this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过在
MPMoviePlayerDidExitFullscreenNotification
上添加通知处理程序来实现此目的,因为一旦用户点击“完成”按钮,该通知就会发送。现在在初始化程序中的某个位置
实现该处理程序:
You can do that by adding a notification handler on
MPMoviePlayerDidExitFullscreenNotification
as that notification gets sent once the user taps on the DONE Button.Somewhere in your initializer
Now implement that handler:
据我所知,单击“完成”按钮时您不会收到通知。但是,单击“完成”按钮后,当电影播放器退出全屏时,您会收到通知。为此,您可以使用 MPMoviePlayerDidExitFullscreenNotification
要观察此通知并采取行动,您需要将以下代码粘贴到包含 IBAction 的类文件中(将其放入
viewDidLoad
方法中):现在您需要在同一个类中创建
exitedFullScreen
方法:最后,在您的
viewDidUnload
方法中,粘贴以下行:解释发生了什么:
“addObserver”代码行在 viewDidLoad 中确保负责处理 moviePlayer 的 viewController 正在监听 MPMoviePlayerDidExitFullScreen 通知。
该行使得当通知到来时, exitedFullScreen 方法被触发,您可以在其中放置单击“完成”按钮时想要运行的代码。
在 viewDidUnload 中,viewController 将被卸载,因此您想要停止监听通知,因此需要删除Observer 部分。
To the best of my knowledge, you can't be notified when the Done button is clicked. You can, however be notified when the movie player exits fullscreen after the Done button is clicked. For this, you use the MPMoviePlayerDidExitFullscreenNotification
To observe and act upon this notification you need to paste the following code in your class file which contains the IBAction (put it in the
viewDidLoad
method):Now you need to create the
exitedFullScreen
method in the same class:Finally, in your
viewDidUnload
method, paste the following line:To explain what's going on:
The "addObserver" line of code in your viewDidLoad makes sure your viewController responsible for handling the moviePlayer is listening to the MPMoviePlayerDidExitFullScreen notification.
That line makes it so that when the notification comes is, the exitedFullScreen method is fired off, where you would put the code you wanted to run when the Done button was clicked.
In the viewDidUnload, the viewController is going to be unloaded so you want to stop listening to the notification, hence the removeObserver part.