首页 > 解决方案 > 如果我尝试以编程方式旋转 iPad 模拟器,它不会旋转

问题描述

我试图在 Xamarin.iOS 中以编程方式旋转模拟器,如下面的代码片段所示,

public void ChangeOrientation(string mode)
{
    // Need to rotate the device to the landscape mode.
    if (mode == "Landscape")
    {
        UIDevice.CurrentDevice.SetValueForKey(new NSNumber((int)UIInterfaceOrientation.LandscapeRight), new NSString("orientation"));
    }
    else
    {
        // Need to rotate the device to the potrait mode.
        UIDevice.CurrentDevice.SetValueForKey(new NSNumber((int)UIInterfaceOrientation.Portrait), new NSString("orientation"));
    }
}

如果我调用上述方法,模拟器应该旋转。实际上,iPhone 模拟器是旋转的。但 iPad 模拟器没有旋转。有什么建议么?

在此先感谢,迪瓦卡。

标签: xamarinxamarin.ios

解决方案


这是工作示例应用程序的链接https://github.com/ramyareddyn/RotationSample

希望能帮助到你!


推荐阅读