请原谅我一个菜鸟问题,这是我的第一个问题,我老老实实地花费了大量精力寻找自己的解决方案。
我有一个带有两个视图控制器的项目。 main on仅是纵向视图,而second(sub)模态视图控制器仅以横向模式呈现。我的目标是让设备的方向单独切换控制器(并提供对模态视图控制器的函数调用,同时从主视图控制器传递某些ivars)同样我想重新定向到肖像到取消模态视图并恢复到起点。
我想这苹果自己的计算器应用程序有多少?任何人都能给我一个关于最符合API的方式的线索吗? 非常感谢你的时间。
我非常希望避免模态视图上的“后退”或“完成”按钮,并且只有在可能的情况下才能使用设备方向来回更改
答案 0 :(得分:3)
对于您想要做的事情,Apple有一个很好的解释和示例代码。请参阅View Controller编程指南中的Creating an Alternate Landscape Interface。
答案 1 :(得分:1)
如果您为观看次数启用了轮播,那么在-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
中您可以像这样检查方向和行为:
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
if(UIInterfaceOrientationIsLandscape(toInterfaceOrientation))
{
//check if modal viewController is already alive
//pop the modal if needed
}
else
{
//destory the modal if its still alive
}
}