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

发布于 2024-09-07 15:05:59 字数 2232 浏览 3 评论 0原文

我正在开发一个应用程序(我的第一个),它基本上是一个 TabBar 应用程序。 更准确的说有: - 登录视图控制器 - 标签栏控制器(登录完成后) - 当 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]];
}

我希望 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");
}

其中一部分好吧,我的意思是从纵向切换到横向是可以的(当我在第一个选项卡中时),选项卡控制器从超级视图中删除,横向视图被添加为子视图。

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

简而言之,当我在横向视图中时,我不知道该怎么做才能移回选项卡栏视图...一旦我身处其中,我就会陷入风景之中。

非常感谢你的帮助,

卢克

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

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

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

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

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

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.

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.

Thanks a lot for your help,

Luc

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

埋情葬爱 2024-09-14 15:05:59

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

Look at the pie chart in CPTestApp-iPhone in the examples folder. It handles rotation by implementing -(void)didRotateFromInterfaceOrientation: and resizing the graph after a rotation.

埋情葬爱 2024-09-14 15:05:59

好吧,我设法解决了这个问题。
事实上,在从纵向移动到横向时,我从窗口子视图中删除了 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文