Iphone:无法从横向视图切换回纵向视图

Iphone:无法从横向视图切换回纵向视图,iphone,rotation,landscape,addsubview,Iphone,Rotation,Landscape,Addsubview,我正在开发一个应用程序(我的第一个),它基本上是一个TabBar应用程序。 更准确地说,有: -登录视图控制器 -选项卡栏控制器(登录完成时) -当选项卡栏的第一个itel从纵向切换到横向时使用的横向视图控制器 因此,当我在第一个选项卡中时,我需要能够移动到横向视图以显示其他一些数据。在我的选项卡栏控制器中,我实现了以下方法: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrien

我正在开发一个应用程序(我的第一个),它基本上是一个TabBar应用程序。 更准确地说,有: -登录视图控制器 -选项卡栏控制器(登录完成时) -当选项卡栏的第一个itel从纵向切换到横向时使用的横向视图控制器

因此,当我在第一个选项卡中时,我需要能够移动到横向视图以显示其他一些数据。在我的选项卡栏控制器中,我实现了以下方法:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if([self selectedIndex] == 0)
    return YES;

return NO;
}


- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];

// Get AppDelegate
MyAppDelegate *delegate = [[UIApplication sharedApplication] delegate];

 if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
 {
     // Remove TabBarView and add graph Landscape View   
     [self.view removeFromSuperview];
     [delegate setSubViewLandscapeViewController];
 }
}
在委托中,我实现了setSubViewLandscapeViewController和setSubViewTabBarController:

- (void)setSubViewTabBarViewController {    
[window addSubview:[tabBarController view]];
}

- (void)setSubViewGraphLandscapeViewController {
[window addSubview:[landscapeViewController view]];
}
- (void)viewWillAppear:(BOOL)animated {
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

NSLog(@"willRotateToInterfaceOrientation");
}
我希望landscapeViewController仅在横向模式下显示,然后(在我的landscapeViewController中):

其中一部分工作正常,我的意思是从纵向视图切换到横向视图是正常的(当我在第一个选项卡中时),tabbarcontroller从SuperView中移除,而横向视图被添加为子视图

问题是。。。我不知道如何切换回纵向模式(然后使用我的代理的setSubViewTabBarViewController加载上一个控制器,即tabBar控制器)。似乎没有一个是旋转定向,旋转定向。。当我实际从横向视图移动设备时触发

简言之,当我在横向视图中时,我不知道该怎么做才能移回tabbar视图。。。一旦我在这里,我就被困在风景中了

非常感谢你的帮助


Luc

查看示例文件夹中CPTestApp iPhone中的饼图。它通过实现
-(void)didRotateFromInterfaceOrientation:
并在旋转后调整图形的大小来处理旋转。

好吧,我设法找到了这个问题的解决方案。 事实上,在从纵向移动到横向时,我从窗口子视图中删除了tabbarcontroller,并添加了landscapeviewcontroller。 看来这不是正确的做法。 相反,我将landscapeViewController添加为tabbarcontroller的子视图,并在从横向转到纵向时将其删除。 我仍然有一个问题,但与景观的y位置,似乎改变了当我做了几次决定性的旋转在一行。。。。 当做
Luc

你好,事实上我想我不是很清楚:(当从纵向模式移动到横向模式时,我需要加载lanscape视图,我最终通过shouldAutorotateToInterfaceOrientation和willRotateToInterfaceOrientation方法实现了这一点。问题是,现在我处于横向模式,我不知道如何处理从横向模式到纵向模式的旋转…正如我所声明的那样UIView仅作为横向视图,在这种情况下是否有触发的方法?非常感谢