[英]Subclassing 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
@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 *)event方法,但是沒有對其調用super。 我打電話給它,一切都固定了。
編輯:請注意,這可以回答原始問題,在進行重大重寫之前,可以更改整個問題
您首先應該找出是否有記錄的方式(某些調用或重寫的方法)來更改導航欄的高度。 我非常懷疑有一個。 而且我也懷疑UIWindow
是否是尋找它的地方-導航欄是UINavigationController的一部分。
假設沒有合法的方法強制高度保持為44px,則可以嘗試以下幾種方法:
-shouldAutoRotate.. { return NO; }
-shouldAutoRotate.. { return NO; }
。 快速檢查一下,如果將最頂層VC的幀簡單地設置為CGRectMake(0,0,480,320);
會發生什么情況CGRectMake(0,0,480,320);
(從您的子類UINavigationController或從子類UIWindow)。 如果一切正常,那么您只需添加自動旋轉部分。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.