0

请考虑下面的代码。它按预期工作 - 正在发送 MPMoviePlayerDidExitFullscreenNotification 通知并调用 ClosePlayer 方法。

using System;
using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.MediaPlayer;
using MonoTouch.UIKit;

public partial class PlayerViewController : MPMoviePlayerController
{
    public PlayerViewController() : base()
    {
        NSNotificationCenter.DefaultCenter.AddObserver("MPMoviePlayerDidExitFullscreenNotification", this.ClosePlayer);
    }

    private void ClosePlayer(NSNotification notification)
    {
        // Do something..
    }
}

然而,这个设计让我觉得很奇怪,我想知道我们是否可以做一些更简单的事情,如下所示:

this.MPMoviePlayerDidExitFullscreenNotification += this.ClosePlayer;

必须通过 NSNotificationCenter 才能监听类本身触发的事件似乎真的很不自然。还是我错过了什么?

另外 - 是否可以以硬编码字符串以外的任何方式指定通知类型(例如 - MPMoviePlayerDidExitFullscreenNotification)?

先感谢您 :)

免责声明:我是 MonoTouch 的菜鸟,拥有 .NET 背景,有些事情感觉很奇怪。

4

1 回答 1

2

我只是偶然发现 MPMoviePlayerController 上有一个可以使用的静态属性:

MPMoviePlayerController.Notifications.ObserveDidExitFullscreen(this.ClosePlayer);
于 2013-07-14T14:28:27.717 回答