子类UIWindow

我只是尝试子类UIWindow,以便我可以拦截一些通知。 随着下面列出的代码,我也进入MainWindow.xib并更新UIWindow对象到我的子类。 它加载好,问题是我的标签栏上的标签没有反应(在下面的例子中,我只添加了一个选项卡,但在我的应用程序,我有多个(这不是问题))。 任何人都可以看到我可能做错了什么? 谢谢。

UISubclassedWindow.h

#import <UIKit/UIKit.h> @interface UISubclassedWindow : UIWindow { } @end 

UISubclassedWindow.m

  #import "UISubclassedWindow.h" @implementation UISubclassedWindow - (id) initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { NSLog(@"init"); } return self; } - (void)makeKeyAndVisible { [super makeKeyAndVisible]; NSLog(@"makeKeyAndVisible"); } - (void)becomeKeyWindow { [super becomeKeyWindow]; NSLog(@"becomeKeyWindow"); } - (void)makeKeyWindow { [super makeKeyWindow]; NSLog(@"makekeyWindow"); } - (void)sendEvent:(UIEvent *)event { } - (void)dealloc { [super dealloc]; } @end 

AppDelegate.h

import

@class UISubclassedWindow;

 @interface My_AppAppDelegate : NSObject <UIApplicationDelegate> { UISubclassedWindow *window; } @property (nonatomic, retain) IBOutlet UISubclassedWindow *window; @end 

AppDelegate.m

 @synthesize window; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { UITabBarController *tabBarController = [[UITabBarController alloc] init]; MainViewController *mainViewController = [[MainViewController alloc] initWithViewType: 0]; UINavigationController *mainNavigationController = [[UINavigationController alloc] initWithRootViewController: mainViewController]; mainNavigationController.title = @"Main"; [[mainNavigationController navigationBar] setBarStyle: UIBarStyleBlack]; [tabBarController setViewControllers: [NSArray arrayWithObjects: mainNavigationController, nil]]; [self.window setRootViewController: tabBarController]; [self.window makeKeyAndVisible]; [mainViewController release]; [mainNavigationController release]; [tabBarController release]; return YES; } 

问题是我包括UIWindows – (void)sendEvent:(UIEvent *)事件方法,但没有调用超级。 我打了个超级电话,一切都修好了。

编辑:请注意,这回答了原来的问题之前,重大改写整个问题

你应该先找出是否有一个文件化的方式(一些调用,或重写的方法)来改变导航栏的高度。 我非常怀疑有一个。 而且我也怀疑UIWindow是否是查找它的地方 – 导航栏是UINavigationController的一部分。

假设没有合法的方法来强制高度保持44px,你可以尝试几件事情:

  1. (不推荐)打破UINavigationController的整个自动旋转机制,像你现在开始做的那样,自己处理视图控制器的旋转,例如从UIWindow。 UINavigationController只会“感觉”一个resize,并不知道它实际上正在旋转。 UINavigationController一定不能旋转,所以-shouldAutoRotate.. { return NO; } -shouldAutoRotate.. { return NO; } 。 作为一个快速检查,看看会发生什么,如果你只是将最上面的VC帧设置为CGRectMake(0,0,480,320); (来自你的子类UINavigationController或从子类UIWindow)。 如果一切仍然正常,那么你只需要添加自动旋转部分。
  2. (推荐)不要依赖UINavigationController来绘制导航栏,而是自己做。 没有太多的乐趣,但99%的保证,你会得到它的工作,它不会在每一个更新的iOS中断。
  3. (中性,快速和肮脏的修复)的景观模式,把你自己的UINavigationBar顶部的常规。