navigationController推送的ViewController不会自动旋转 [英] navigationController pushed ViewControllers won't autorotate

查看:56
本文介绍了navigationController推送的ViewController不会自动旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难让导航控制器正确地自动旋转.该显示将在初始视图(根视图控制器)上自动旋转,但不会在任何按下的新视图上旋转.它保持推入时原始视图的视图方向.

I'm having difficulty getting a navigation controller to autorotate correctly. The display will autorotate on the initial view (root view controller), but it will not rotate on any new views that are pushed on. It keeps the view orientation that the initial view had when pushed.

在我的App Delegate中,我有一个导航控制器并将其推入视图.

In my App Delegate I have a navigation controller and push it's view.

[window addSubview:navigationController.view];
[window makeKeyAndVisible];

在根视图控制器中,我允许所有方向,然后将其他视图推入控制器的堆栈中.

In the root view controller I allow all orientations and I push other views onto the controller's stack.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
     return YES;
}

ParkingListController *parklc = [[ParkingListController alloc] autorelease];
[[self navigationController] pushViewController:parklc animated:YES];

我看到是的,我们应该!"在加载新视图时记录一次,但是在实际旋转设备时不会触发.

I see "Yes, we should!" logged once when the new view loads, but it does not fire when the device is actually rotated.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    NSLog(@"Yes, we should!");
    return YES;
}

我没有任何初始化覆盖,info.plist列出了所有四个方向.

I do not have any init overrides and the info.plist lists all four orientations.

我想念什么?谢谢!

EDIT 2011-07-07:

奇怪的是,当您从表格视图中选择一个项目时按下的地图视图会自动旋转!为什么无法旋转来自其的表格视图?

Strangely the map view that is pushed on when you select an item from the table view does autorotate! Why can it rotate when the table view it came from cannot?

推荐答案

您正在使用UINavigationController,并且旋转应返回true.请扩展UINavigationController并在界面"构建器中使用扩展的类.

You are using a UINavigationController and it should return true for rotation. Please extend UINavigationController and use the extended class in Interface builder.

#import <Foundation/Foundation.h>
@interface IRUINavigationController : UINavigationController {
}
@end

#import "IRUINavigationController.h"
@implementation IRUINavigationController
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
    [self.visibleViewController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
} 
@end

我已经使用了很多项目,并且可以正常工作.

I have used this is many projects and it works.

这篇关于navigationController推送的ViewController不会自动旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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