首页 > 解决方案 > 如何直接从其事件(ObserveOrientationDidChange)中获取强类型的方向?

问题描述

编辑:建议的副本确实提供了一种获取方向的方法。谢谢你。但它没有显示如何以Microsoft 文档提到的方式获取强类型通知。

ObserveOrientationDidChange的文档说:

OrientationDidChangeNotification 常量的强类型通知。[强调我的]

但是那里的例子只是没用的:

// Access strongly typed args
Console.WriteLine ("Notification: {0}", args.Notification);

所以设置好之后:

var notification = UIDevice.Notifications.ObserveOrientationDidChange(OrientationChanged);

我尝试将其转换为UIDeviceOrientation

void OrientationChanged(object sender, NSNotificationEventArgs e)
{            
    UIDeviceOrientation o = (UIDeviceOrientation)e.Notification;
}

但我收到一个错误:

错误 CS0030 无法将类型“Foundation.NSNotification”转换为“UIKit.UIDeviceOrientation”

那么如何该事件中获取强类型值(如 Microsoft 上述文档中所述)?

标签: c#iosswiftxamarinxamarin.ios

解决方案


推荐阅读