Поделиться через


UIKeyboard.WillShowNotification Свойство

Определение

Константа уведомлений для WillShow

[Foundation.Advice("Use UIKeyboard.Notifications.ObserveWillShow helper method instead.")]
[Foundation.Field("UIKeyboardWillShowNotification", "UIKit")]
[ObjCRuntime.Unavailable(ObjCRuntime.PlatformName.TvOS, ObjCRuntime.PlatformArchitecture.All, null)]
public static Foundation.NSString WillShowNotification { [ObjCRuntime.Unavailable(ObjCRuntime.PlatformName.TvOS, ObjCRuntime.PlatformArchitecture.All, null)] get; }
member this.WillShowNotification : Foundation.NSString

Значение свойства

Константа NSString должна использоваться в качестве токена для NSNotificationCenter.

Атрибуты

Комментарии

Эту константу можно использовать с для NSNotificationCenter регистрации прослушивателя для этого уведомления. Это NSString вместо строки, так как эти значения можно использовать в качестве маркеров в некоторых собственных библиотеках, а не только для их фактического содержимого строк. Параметр notification для обратного вызова содержит дополнительные сведения, относящиеся к типу уведомления.

Если вы хотите подписаться на это уведомление, можно использовать удобный UIKeyboard.Notificationsметод ,ObserveWillShow который предоставляет строго типизированный доступ к параметрам уведомления.

В следующем примере показано, как использовать строго типизированный класс Notifications, чтобы вывести догадки из доступных свойств в уведомлении:

//
// Lambda style
//

// listening
notification = UIKeyboard.Notifications.ObserveWillShow ((sender, args) => {
    /* Access strongly typed args */
    Console.WriteLine ("Notification: {0}", args.Notification);

    Console.WriteLine ("FrameBegin", args.FrameBegin);
    Console.WriteLine ("FrameEnd", args.FrameEnd);
    Console.WriteLine ("AnimationDuration", args.AnimationDuration);
    Console.WriteLine ("AnimationCurve", args.AnimationCurve);
});

// To stop listening:
notification.Dispose ();

//
// Method style
//
NSObject notification;
void Callback (object sender, UIKit.UIKeyboardEventArgs args)
{
    // Access strongly typed args
    Console.WriteLine ("Notification: {0}", args.Notification);

    Console.WriteLine ("FrameBegin", args.FrameBegin);
    Console.WriteLine ("FrameEnd", args.FrameEnd);
    Console.WriteLine ("AnimationDuration", args.AnimationDuration);
    Console.WriteLine ("AnimationCurve", args.AnimationCurve);
}

void Setup ()
{
    notification = UIKeyboard.Notifications.ObserveWillShow (Callback);
}

void Teardown ()
{
    notification.Dispose ();
}

В следующем примере показано, как использовать уведомление с API DefaultCenter:

// Lambda style
NSNotificationCenter.DefaultCenter.AddObserver (
        UIKeyboard.WillShowNotification, (notification) => {Console.WriteLine ("Received the notification UIKeyboard", notification); }


// Method style
void Callback (NSNotification notification)
{
    Console.WriteLine ("Received a notification UIKeyboard", notification);
}

void Setup ()
{
    NSNotificationCenter.DefaultCenter.AddObserver (UIKeyboard.WillShowNotification, Callback);
}

Применяется к