Edytuj

Udostępnij za pośrednictwem


UIDevice.Notifications.ObserveOrientationDidChange Method

Definition

Overloads

ObserveOrientationDidChange(EventHandler<NSNotificationEventArgs>)

Strongly typed notification for the OrientationDidChangeNotification constant.

ObserveOrientationDidChange(NSObject, EventHandler<NSNotificationEventArgs>)

Strongly typed notification for the OrientationDidChangeNotification constant.

ObserveOrientationDidChange(EventHandler<NSNotificationEventArgs>)

Strongly typed notification for the OrientationDidChangeNotification constant.

public static Foundation.NSObject ObserveOrientationDidChange (EventHandler<Foundation.NSNotificationEventArgs> handler);
static member ObserveOrientationDidChange : EventHandler<Foundation.NSNotificationEventArgs> -> Foundation.NSObject

Parameters

handler
EventHandler<NSNotificationEventArgs>

Method to invoke when the notification is posted.

Returns

Token object that can be used to stop receiving notifications by either disposing it or passing it to RemoveObservers(IEnumerable<NSObject>)

Remarks

The following example shows how you can use this method in your code

//
// Lambda style
//

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

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

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

void Setup ()
{
    notification = UIDevice.Notifications.ObserveOrientationDidChange (Callback);
}

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

Applies to

ObserveOrientationDidChange(NSObject, EventHandler<NSNotificationEventArgs>)

Strongly typed notification for the OrientationDidChangeNotification constant.

public static Foundation.NSObject ObserveOrientationDidChange (Foundation.NSObject objectToObserve, EventHandler<Foundation.NSNotificationEventArgs> handler);
static member ObserveOrientationDidChange : Foundation.NSObject * EventHandler<Foundation.NSNotificationEventArgs> -> Foundation.NSObject

Parameters

objectToObserve
NSObject

The object to observe.

handler
EventHandler<NSNotificationEventArgs>

Method to invoke when the notification is posted.

Returns

Token object that can be used to stop receiving notifications by either disposing it or passing it to RemoveObservers(IEnumerable<NSObject>)

Remarks

This method can be used to subscribe for OrientationDidChangeNotification notifications.

// Listen to all notifications posted for any object
var token = UIDevice.Notifications.ObserveOrientationDidChange ((notification) => {
	Console.WriteLine ("Observed OrientationDidChangeNotification!");
};

// Listen to all notifications posted for a single object
var token = UIDevice.Notifications.ObserveOrientationDidChange (objectToObserve, (notification) => {
	Console.WriteLine ($"Observed OrientationDidChangeNotification for {nameof (objectToObserve)}!");
};

// Stop listening for notifications
token.Dispose ();

Applies to