【问题标题】:Iphone: Cannot switch back from my landscape view to a portrait viewIphone:无法从我的横向视图切换回纵向视图
【发布时间】:2010-06-30 13:54:33
【问题描述】:

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

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

- (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]];
}

我希望landscapeViewController 仅在横向模式下显示,然后(在我的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、.. 被触发...

简而言之,当我在横向视图中时,我不知道该怎么做才能回到标签栏视图......一旦我进入这个视图,我就有点卡在横向视图中了。

非常感谢您的帮助,

卢克

【问题讨论】:

    标签: iphone rotation landscape addsubview


    【解决方案1】:

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

    【讨论】:

    • 你好,其实我觉得我不是很清楚 :( 从纵向模式切换到横向模式时我需要加载横向视图,我最终通过 shouldAutorotateToInterfaceOrientation 和 willRotateToInterfaceOrientation 方法做到了这一点. 问题是,现在我处于横向模式,我不知道如何处理从横向模式到纵向模式的旋转...因为我已将 UIView 声明为仅横向,在这种情况下是否有触发方法?谢谢很多
    【解决方案2】:

    好吧,我设法找到了解决这个问题的方法。 事实上,在从纵向移动到横向时,我从窗口子视图中删除了 tabbarcontroller 并添加了 Landscapeviewcontroller。 看来这不是正确的做法。 相反,我将 LandscapeViewController 添加为 tabbarcontroller 的子视图,并在从横向变为纵向时将其删除。 我仍然有一个问题,但是当我连续进行几次旋转时,横向视图的 y 位置似乎发生了变化...... 问候, 卢克

    【讨论】:

      猜你喜欢
      • 2012-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-27
      相关资源
      最近更新 更多