Xamarin iOS ObserveOrientationDidChange横向或纵向 [英] Xamarin iOS ObserveOrientationDidChange Landscape or Portrait

查看:29
本文介绍了Xamarin iOS ObserveOrientationDidChange横向或纵向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检测用户何时将设备旋转到横向.我可以使用以下代码检测方向何时更改:

I need to detect when the user rotate the device to Landscape orientation. I can detect when the orientation changed with the code below:

UIDevice.CurrentDevice.BeginGeneratingDeviceOrientationNotifications();
this.orientationObserver = UIDevice.Notifications.ObserveOrientationDidChange(MyRotationCallback);

private void MyRotationCallback(object sender, NSNotificationEventArgs e)
{
    // Landscape or Portrait ?
}

它可以工作,但是我无法确定它是否已更改为横向或纵向.我怎么能检测到这个?

It works, but I can't tell if it was changed to landscape or portrait. How I can I detect this?

推荐答案

检查属性:

UIDevice.CurrentDevice.Orientation

值:

LandscapeLeft
PortraitUpsideDown
LandscapeRight
Portrait

示例设置:

在您的 ViewDidLoad (或类似名称)中:

Foundation.NSNotificationCenter.DefaultCenter.AddObserver(new NSString("UIDeviceOrientationDidChangeNotification"), DeviceRotated);

委托/操作:

void DeviceRotated(NSNotification notification)
{
    System.Diagnostics.Debug.WriteLine(UIDevice.CurrentDevice.Orientation);
}

输出:

LandscapeLeft
PortraitUpsideDown
LandscapeRight
Portrait

这篇关于Xamarin iOS ObserveOrientationDidChange横向或纵向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆