Subclassification of UIWindow

I'm just trying to subclass UIWindow to catch some notifications. Along with the code below, I also go to MainWindow.xib and update the UIWindow object for my subclass. It loads normally, the problem is that the tabs on the tab bar do not respond (in the example below I added only one tab, but in my application I have several (this is not a problem)). Can anyone see what I can do wrong? Thanks.

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; } 
+4
source share
2 answers

The problem was that I turned on the UIWindows event method - (void) sendEvent: (UIEvent *), but did not call it super. I called super, and everything was fixed.

+4
source

edit: note that this answers the original question before the main rewrite the whole problem

First you need to find out if there is a documentary way (some kind of call or an overridden method) to change the height of the navigation bar. I very much doubt that he is. And I also doubt that UIWindow is a place to search - the navigation bar is part of the UINavigationController.

Assuming there is no legal way to make the height remain 44px, you can try a few things:

  • (not recommended) tear the whole UINavigationController auto-typing machine, handle the rotation of the view controllers yourself, for example. from UIWindow, how are you starting now. The UINavigationController will only “feel” the resize and does not know that it is actually spinning. UINavigationController should not rotate, so -shouldAutoRotate.. { return NO; } -shouldAutoRotate.. { return NO; } . As a quick check, see what happens if you just set the top VC frame to CGRectMake(0,0,480,320); (either from your subclass of UINavigationController, or from a subclass of UIWindow). If everything still works fine, you need to add some autorotation.
  • (recommended) Do not rely on the UINavigationController to draw navigation bars, but do it yourself. It’s not very fun to do, but 99% ensures that you get it working, and it won’t break with every iOS update.
  • (neutral, quick, and dirty fix) for landscape mode, add your own UINavigationBar on top of the regular one.
+2
source

Source: https://habr.com/ru/post/1390751/


All Articles