iOS6设备上是否应忽略带选项卡栏控制器的AutoRotateTointerFaceOrientation
我有一个使用6.1 SDK的Monotouch 6.0.10 iPhone应用程序,但目标是iOS 4.0及更高版本,我尝试使用ShouldAutorotateToInterfaceOrientation将其中一个视图强制为纵向,但没有成功。我意识到它现在已被弃用,但仍然需要支持iOS4/iOS5设备 为了尝试隔离问题,我编写了一个最小测试应用程序。它没有XIB,有一个带一个选项卡的UITABBARC控制器。该选项卡有一个UINavigationController,UINavigationController有一个UIViewController(带有可单击的hello world按钮) 在AppDelegate中,我有:iOS6设备上是否应忽略带选项卡栏控制器的AutoRotateTointerFaceOrientation,ios6,xamarin.ios,screen-rotation,Ios6,Xamarin.ios,Screen Rotation,我有一个使用6.1 SDK的Monotouch 6.0.10 iPhone应用程序,但目标是iOS 4.0及更高版本,我尝试使用ShouldAutorotateToInterfaceOrientation将其中一个视图强制为纵向,但没有成功。我意识到它现在已被弃用,但仍然需要支持iOS4/iOS5设备 为了尝试隔离问题,我编写了一个最小测试应用程序。它没有XIB,有一个带一个选项卡的UITABBARC控制器。该选项卡有一个UINavigationController,UINavigationCo
tabController = new TabController();
window.RootViewController = tabController;
在UIDABBARCONTROLLER和UINavigationController中,我有:
public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation)
{
return true;
}
public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation)
{
if ( toInterfaceOrientation == UIInterfaceOrientation.Portrait )
{
return true;
}
else
{
return false;
}
}
在UIViewController中,我有:
public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation)
{
return true;
}
public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation)
{
if ( toInterfaceOrientation == UIInterfaceOrientation.Portrait )
{
return true;
}
else
{
return false;
}
}
好吧,至少在iOS 6.1设备上,那些应该自动旋转的指针面方向似乎被完全忽略了。那个里的断点并没有到达,若我强迫它们在任何情况下都返回false,那个么旋转仍然会发生
我的理解是,ShouldAutomaticallyForwardRotationMethods默认为true,因此似乎无法提供解决方案。除了格伦·施密特(Glen Schmidt)在这里提出的建议外,我在梳理论坛时运气不佳:但不幸的是,我不知道如何将其转化为MonoTouch:
引述
取消报价
我也明白,我甚至不希望仅通过ShouldAutoRotate/SupportedInterfaceOrientations为我的iOS6用户解决这个问题,因为这会导致iOS4/IOS5的旋转失败
非常感谢您的任何建议
比尔。经过一番周折,找到了一个有效的解决方案。也许有人能改进这一点 问题 我的应用程序基于SDK 6.1,以iOS4、iOS5和iOS6设备为目标。它需要允许所有屏幕旋转,但必须固定在纵向的屏幕除外。该应用程序有一个UIAbbarController,大多数选项卡都有一个UINavigationController,下面有堆叠视图 解决方案 对于iOS4/iOS5用户,关键是应用程序根视图控制器(在我的例子中是选项卡栏控制器)中不推荐的ShouldAutorotateToInterfaceOrientation()方法。此方法不会在任何其他视图控制器中自动调用,但根视图控制器当然可以在当前视图控制器中调用相同名称的方法 对于iOS6用户,密钥是应用程序根视图控制器中的ShouldAutorotate()/getSupportedInterfaceOrientions()。同样,这些方法不会在任何其他视图控制器中自动调用,但根视图控制器可以在当前视图控制器中调用相同名称的方法 对于原始帖子中描述的我的简单测试应用程序: 在AppDelegate/FinishedLaunching中:
window.RootViewController = tabController;
在AppDelegate中:
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations (UIApplication application, UIWindow forWindow)
{
return UIInterfaceOrientationMask.All;
}
在TabController中:
public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation) // iOS4/iOS5 only
{
try
{
UINavigationController navController = (UINavigationController)SelectedViewController;
UIViewController targetController = navController.ViewControllers[0];
if ( targetController.Title == "Greetings")
{
if ( toInterfaceOrientation == UIInterfaceOrientation.Portrait )
{
return true;
}
else
{
return false;
}
}
}
catch
{
return true;
}
return true;
}
public override bool ShouldAutorotate() // iOS6+ only
{
return true;
}
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations() // iOS6+ only
{
try
{
UINavigationController navController = (UINavigationController)SelectedViewController;
UIViewController targetController = navController.ViewControllers[0];
return targetController.GetSupportedInterfaceOrientations();
}
catch
{
return UIInterfaceOrientationMask.All;
}
return UIInterfaceOrientationMask.All;
}
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
{
try
{
UINavigationController navController = (UINavigationController)SelectedViewController;
if ( navController.Title == "Tracking" ) // Are we on the Tracking tab?
{
// Yes. Looking for RedLaser's BarcodePickerController
UIViewController targetController = navController.ViewControllers[1]; // BarcodePicker would be second on nav stack
string controllerType = targetController.GetType().Name;
if ( controllerType == "BarcodePickerController" ) // Is this BarcodePicker?
{
return UIInterfaceOrientationMask.Portrait; // Yes, force portrait orientation
}
}
else
{
return UIInterfaceOrientationMask.All; // No, allow any orientation
}
}
catch
{
return UIInterfaceOrientationMask.All; // Not BarcodePicker, allow any orientation
}
return UIInterfaceOrientationMask.All;
}
在需要纵向显示的视图控制器中:
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations() // iOS6+ only
{
return UIInterfaceOrientationMask.Portrait;
}
我的实际应用程序需要一些更精细的东西,但思路相同。例如,在tabbarcontroller中:
public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation) // iOS4/iOS5 only
{
try
{
UINavigationController navController = (UINavigationController)SelectedViewController;
UIViewController targetController = navController.ViewControllers[0];
if ( targetController.Title == "Greetings")
{
if ( toInterfaceOrientation == UIInterfaceOrientation.Portrait )
{
return true;
}
else
{
return false;
}
}
}
catch
{
return true;
}
return true;
}
public override bool ShouldAutorotate() // iOS6+ only
{
return true;
}
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations() // iOS6+ only
{
try
{
UINavigationController navController = (UINavigationController)SelectedViewController;
UIViewController targetController = navController.ViewControllers[0];
return targetController.GetSupportedInterfaceOrientations();
}
catch
{
return UIInterfaceOrientationMask.All;
}
return UIInterfaceOrientationMask.All;
}
public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
{
try
{
UINavigationController navController = (UINavigationController)SelectedViewController;
if ( navController.Title == "Tracking" ) // Are we on the Tracking tab?
{
// Yes. Looking for RedLaser's BarcodePickerController
UIViewController targetController = navController.ViewControllers[1]; // BarcodePicker would be second on nav stack
string controllerType = targetController.GetType().Name;
if ( controllerType == "BarcodePickerController" ) // Is this BarcodePicker?
{
return UIInterfaceOrientationMask.Portrait; // Yes, force portrait orientation
}
}
else
{
return UIInterfaceOrientationMask.All; // No, allow any orientation
}
}
catch
{
return UIInterfaceOrientationMask.All; // Not BarcodePicker, allow any orientation
}
return UIInterfaceOrientationMask.All;
}