Iphone:无法从我的横向视图切换回肖像视图

问题描述:

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

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

- (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:我想landscapeViewController只在横向模式下显示

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

- (void)setSubViewGraphLandscapeViewController { 
[window addSubview:[landscapeViewController view]]; 
} 

,然后我(在我的landscapeViewController):

- (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"); 
} 

这部分工作正常,我的意思是从肖像切换到风景是好的(当我在第一个标签中)时,tabbarcontroller将从SuperView中移除,而横向视图将作为子视图添加。

事情是......我不知道如何切换回肖像模式(然后使用我的委托的setSubViewTabBarViewController加载前一个控制器,tabBar一个)。似乎没有任何willRotateToOrientation,willRotateFromOrientation,..当我实际上从横向视图移动设备时触发...

总之,当我在景观视图时,我不知道该怎么做才能移回来到tabbar视图...我有一种卡在横向视图,一旦我在这一个。

非常感谢您的帮助,

吕克

嗯,我设法得到了解决这个问题的方法。 事实上,从纵向移动到风景时,我从窗口子视图中删除了tabbarcontroller,而是添加了landscapeviewcontroller。 看来这不是正确的事情。 相反,我将landscapeViewController作为tabbarcontroller的子视图添加,并在从横向到纵向时将其删除。 我仍然有一个问题,但与这似乎当我连续做几decive旋转变化.... 关于景观视野的y位置, 吕克

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

+0

你好,其实嘛,我想我是不是真的很清楚:( 我需要加载一个lanscape视图,当从纵向模式转换为横向模式时,我finnaly设法通过shouldAutorotateToInterfaceOrientation和willRotateToInterfaceOrientation方法来处理这个问题。现在我正处于横向模式,我不知道如何处理从横向模式到纵向模式的旋转......因为我已经将UIView声明为横向模式,在这种情况下是否触发了一种方法?非常感谢 – Luc 2010-07-01 17:04:19