gpt4 book ai didi

c# - 无法在 Portrait 中锁定一个 View Controller ,xamarin IOS

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:55:05 28 4
gpt4 key购买 nike

我试图让一个 View Controller 纵向锁定,同时允许所有其他 View 为任何方向。这就是我试图放入我的 homeViewController 中的内容(我想保持纵向的那个)。

public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
{
return UIInterfaceOrientationMask.Portrait;
}
public override UIInterfaceOrientation PreferredInterfaceOrientationForPresentation()
{
return UIInterfaceOrientation.Portrait;
}
public override bool ShouldAutorotate()
{
return false;
}

我正尝试在 c# 中的 xamarin 中执行此操作。有人有什么建议吗?

最佳答案

在 AppDelegate.cs 中添加这个

    public bool RestrictRotation
{
get;
set;
}

并将其添加到同一个 AppDelegate.cs 中,但在 FinishedLaunching() 方法之后

    [Export("application:supportedInterfaceOrientationsForWindow:")]
public UIInterfaceOrientationMask GetSupportedInterfaceOrientations(UIApplication application, IntPtr
forWindow)
{
if (this.RestrictRotation)
return UIInterfaceOrientationMask.Portrait;
else
return UIInterfaceOrientationMask.All;
}

将以下内容添加到您希望制作肖像的每个 View Controller

    public override void ViewDidLoad()
{
base.ViewDidLoad();
this.RestrictRotation(true);
// Perform any additional setup after loading the view, typically from a nib.
}

public override bool ShouldAutorotate()
{
return false;
}

public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
{
return UIInterfaceOrientationMask.Portrait;
}

public override UIInterfaceOrientation PreferredInterfaceOrientationForPresentation()
{
return UIInterfaceOrientation.Portrait;
}

void RestrictRotation(bool restriction)
{
AppDelegate app = (AppDelegate)UIApplication.SharedApplication.Delegate;
app.RestrictRotation = restriction;
}

关于c# - 无法在 Portrait 中锁定一个 View Controller ,xamarin IOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40533007/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com