在方法应用程序中:AppDelegate中的didFinishLaunchingWithOptions我启动一个视图控制器并添加到导航视图控制器,该控制器成为窗口根视图控制器。 因为我的iPad应用程序只是水平方向,所有我的视图控制器都是为横向制作的。
以下是代码:
self.myViewController = [[MyViewController alloc] init];
self.myNavigationController = [[MyNavigationController alloc] initWithRootViewController: self.myViewController];
self.window.rootViewController = self.myNavigationController;
[self.window makeKeyAndVisible];
return YES;
当我在“self.window.rootViewController = self.myNavigationController;”上放置断点时在控制台中划线并调用以显示视图详细信息,我得到以下信息: $ 0 = 0x0c89d010>
我读的矩形是方向模式(1024宽度和748高度)
“return YES”上的下一个断点告诉我这个: $ 1 = 0x0c89d010>
复制一个对象(据我所知)和改变方向(768宽度和1004高度)
这仅在iOS5中发生,但iOS6按预期工作
我应该知道MakeKeyAndVisible方法有任何已知问题吗? 或者可能是我缺乏理解makeKeyAndVisible如何工作
答案 0 :(得分:0)
尝试使用其中的所有方向方法创建自定义UINavigationController,并在您的应用中使用它。
就像这样
<强> CustomNavigationController.h 强>
#import <UIKit/UIKit.h>
@interface CustomNavigationController : UINavigationController
@end
<强> CustomNavigationController.m 强>
#import "CustomNavigationController.h"
@interface CustomNavigationController ()
@end
@implementation CustomNavigationController
//overriding shouldAutorotateToInterfaceOrientation method for working in navController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return [self.topViewController shouldAutorotateToInterfaceOrientation];
}
//other methods
这样,您的方向将在相应的viewCotrollers中相应地工作。