Subclass of UITabBarController to set its scope

I'm having problems resizing the UITabBarController, since I want it to occupy the bottom half of the screen. It seems to be forcing itself to display the full height of the screen (minus the status bar if displayed).

I tried to subclass it and change the controller view frame to methods such as viewWillAppear;, but it just doesn't work. There are times when I can make it change its position, but as soon as another tab is selected or if another view controller is presented in front of it, it will change to full screen!

I tried to set the UIWindow (to which the tab bar controller was added) in autoresizesSubviews:NOand the tab bar autoresizingMask:UIViewAutoresizingNone, but it does not!

Any help would be greatly appreciated!

+3
source share
1 answer

I experimented with this and decided that tabBarController will automatically resize its view and undo all your changes if one of the following events occurs:

  • the value of selectedViewController changes;
  • interface orientation changes;
  • the tab bar (re) is loaded and placed inside the viewport /.

I managed to get the UITabBar view to remain constant by registering for all of the above events and then calling the custom resize method from them.

You can watch the changes in selectedViewController using KVO, for example:

[tabBarController addObserver:self forKeyPath:@"selectedViewController" options:NSKeyValueObservingOptionNew context:NULL]

. , , , UIViewController . : (1) UIDevice (2) . , UIDevice, , , . :

// In a header somewhere (Prefix.pch works).

extern NSString *const kOrinetationNotification;
extern NSString *const kOrinetationNotificationOrientationKey;

// in an instance of UIViewController

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
  [[NSNotificationCenter defaultCenter] postNotificationName:kOrientationNotification object:self userInfo:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:toInterfaceOrientation] forKey:kOrientationNotificationOrientationKey]];
  // do other stuff
}

// in your application delegate (or other dedicated object) init method

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationDidChange:) name:kOrientationNotification object:nil];

, , - , . , , , , .

+4

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


All Articles