iPhone:无法从我的横向视图切换回纵向视图 [英] Iphone: Cannot switch back from my landscape view to a portrait view

查看:145
本文介绍了iPhone:无法从我的横向视图切换回纵向视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am working on an app (my first one), which is basically a TabBar app. To be more precise there are: - a login view controller - a tab bar controller (when login is done) - a landscape view controller that is used when the first itel of the TabBar is switch from Portrait to Landscape.

因此,当我处于第一个标签中时,我需要能够移至横向视图以显示其他数据.在我的标签栏控制器中,我实现了以下方法:

So, when I am in the first tab, I need to be able to move to landscape view to display some other data. In my tab bar controller, I have implemented those methods:

- (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:

In the delegate, I have implemented the setSubViewLandscapeViewController and the setSubViewTabBarController:

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

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

我希望landscapeViewController仅在横向模式下显示,然后(在我的landscapeViewController中):

I want the landscapeViewController to display only in landscape mode, I have then (in my 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中删除,然后将横向视图添加为子视图.

A part of this works fine, I mean the switch from portrait to landscape is ok (when I am in the first tab), the tabbarcontroller is remove from the SuperView and the landscape view is added as a subview instead.

问题是...我不知道如何切换回纵向模式(然后使用我的委托的setSubViewTabBarViewController加载上一个控制器,即tabBar).当我实际上从横向视图中移动设备时,似乎不会触发willRotateToOrientation,willRotateFromOrientation,.....

The thing is... I do not know how to switch back to portrait mode (and then load the previous controller, the tabBar one using the setSubViewTabBarViewController of my delegate). It seems none of the willRotateToOrientation, willRotateFromOrientation, .. are triggered when I actually move the device from the landscape view...

简而言之,当我进入风景视图时,我不知道该怎么做才能回到标签栏视图...进入这个视图后,我有点陷入风景视图中.

In short, when I am in the landscape view I do not know what to do to move back to the tabbar view... I am kind of stuck in the landscape view once I am in this one.

非常感谢您的帮助,

吕克

推荐答案

好吧,我设法解决了这个问题. 实际上,从纵向移动到横向时,我从窗口子视图中删除了tabbarcontroller,而是添加了landscapeviewcontroller. 看来这不是正确的事情. 相反,我将landscapeViewController添加为tabbarcontroller的子视图,并在从横向转到纵向时将其删除. 但是我仍然对风景视图的y位置有问题,当我连续几次旋转旋转时,似乎会改变.... 问候, 卢克

Well, I managed to get a solution for this problem. In fact, while moving from portrait to landscape I removed the tabbarcontroller from window subview and add the landscapeviewcontroller instead. It seems it was not the correct thing to do. Instead, I add the landscapeViewController as subview of the tabbarcontroller and remove it when going from landscape to portrait. I still have a problem however with the y position of the landscape view which seems to changes when I do several decive rotation in a row.... Regards, Luc

这篇关于iPhone:无法从我的横向视图切换回纵向视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆