Iphone 如何在tabbar应用程序中将视图旋转为横向视图
我有一个基于tabbar的应用程序 我在Interface Builder中构建了两个视图,一个是纵向视图,另一个是横向视图 现在,我想要一些类似iPod的应用程序。我希望景观视图是全屏的,并隐藏选项卡栏和状态栏 我将这一点作为工作的基础:Iphone 如何在tabbar应用程序中将视图旋转为横向视图,iphone,ios,cocoa-touch,Iphone,Ios,Cocoa Touch,我有一个基于tabbar的应用程序 我在Interface Builder中构建了两个视图,一个是纵向视图,另一个是横向视图 现在,我想要一些类似iPod的应用程序。我希望景观视图是全屏的,并隐藏选项卡栏和状态栏 我将这一点作为工作的基础: - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration {
if (self.landscape) {
if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
{
self.view = self.portrait;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(360));
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
self.view = self.landscape;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
self.view = self.landscape;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
}
else
{
self.view = self.portrait;
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-180));
}
}
}
但所有的工作都很混乱。景观视图未正确填充该区域,控件位于错误的位置,与最初设计的位置不同
另外,我还没有找到隐藏其他所有内容的方法…您可以通过调用
setStatusBarHidden:(BOOL)
在UIApplication引用上,如下所示
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[application setStatusBarHidden:YES];
}
要摆脱选项卡栏,可以在Interface builder中为代码和调用创建一个引用出口
[myUITabBar removeFromSuperview];
这可能行得通,虽然我还没有测试过,但对于其他问题,我不是100%,以前没有解决过这些问题。好的,这就是我所做的:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration {
if (self.landscape) {
if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
{
self.view = self.portrait;
//self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(360));
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
self.view = self.landscape;
//self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
self.view = self.landscape;
//self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
}
else
{
self.view = self.portrait;
//self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-180));
}
}
}
现在,在AppDelegate中:
- (void) didRotate:(NSNotification *)notification
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
[UIView beginAnimations:nil context:NULL];
if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight)
{
[tabBarController.view setAlpha:0.0];
[tabBarController.view removeFromSuperview];
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
} else {
[tabBarController.view setAlpha:1.0];
[[UIApplication sharedApplication] setStatusBarHidden:NO animated:NO];
}
[UIView commitAnimations];
}
但是,如何设置当前视图以及如何恢复tabbar?当我查看iPod应用程序时,我觉得tabbar控制器视图没有以任何方式被替换或修改。我认为tabbarcontroller视图和coverflow视图之间存在渐变过渡 如果我是你,我会尝试(不确定这是否可行)使用coverflow控制器,其视图显示在tabBarController视图的顶部。If将阻止tabBarController自动旋转其视图,但此时我将淡出其视图并淡入coverflow视图,这将只是横向视图 我不知道状态栏是否会有一个正确的行为,我让你整理了很多细节,但在任何情况下,我认为最好有两个单独的控制器,一个显示在横向,另一个(选项卡栏)在纵向
希望这会对您有所帮助。似乎有相当多的程序员希望有一个选项卡栏项目,将他们带到横向视图全屏(无状态栏、无选项卡栏),然后返回 我已经在苹果开发者论坛上发布了一条关于这是否确实可行的查询,但还没有得到回复 为什么这么难?(对不起,这是一个新手问题?似乎有些相当明显的事情不难)我在网上还没有找到一个明确的答案。看看苹果的“AlternateView”示例代码 其基本思想是,您可以通过通知检测设备的物理方向,然后“modally”激活新的视图控制器,并让它请求全屏显示。通过使shouldAutorotate。。。只对一个方向返回YES,因为您是通过通知手动执行所有这些操作的。更改物理方向时,将显示或取消显示模态视图控制器