UITabBarController - start frame and resize

I found this: A subclass of UITabBarController to set up its frame , which explains how to achieve what I was aiming for in return. To rephrase the message there, you need to register to receive notifications when the selected TabBarController view is selected, and then apply your geometry. Otherwise, it is reset by the TabBarController.


I am trying to resize my UITabBarController to show a message with a high status of 20px when certain tasks are performed. Curiously, if I go through a method that resizes the TabBarController, the origin of the frame will change.

When the view first appears, the source UITabBarController y is set to 0. Despite the fact that applicationatioinScreen y.origin is 20. If I changed the size when I first loaded the application, everything would be turned off. Subsections are not changed. After the first resize, if I look at another tab, the TabBarController will adjust to the desired size, and subsequent calls to the resize method will confirm this.

This is how I install the UITabBarcontroller:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {   
    UITabBarController *tabBarController = [[UITabBarController alloc] init];
    [tabBarController setViewControllers:[AppController getGroupViewControllerArray] animated:NO];
    [window addSubview:tabBarController.view]; 
    [window makeKeyAndVisible]; 
    return YES;
}

And this is how I resize the TabBarController:

-(void)resizeTabToShowActivity {

    CGRect newFrame = mainTabBarController.view.frame;
    CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];
    newFrame.origin.y = applicationFrame.origin.y + 20;
    newFrame.size.height = applicationFrame.size.height - 20;
    mainTabBarController.view.frame = newFrame;

}

I noticed that if I resized right after installing TabBarController in the window, everything will be fine. For debugging purposes, I also moved the resize method to AppDelegate, and there is still no joy.

thank

+3
source share
3 answers

UITabBarController, UIViewController UIViewController .

UIViewController

// .h file
@interface MyTabBarViewController : UIViewController <UITabBarControllerDelegate>
@property(nonatomic, strong) IBOutlet UITabBarController *tbc;
@end

// .m file
@implementation MyTabBarViewController

@synthesize tbc=_tbc;

- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
    if (_tbc == nil) {
        CGRect frame = [[UIScreen mainScreen] bounds];
        // arbitrary numbers, just to illustrate the point
        CGRect smallFrame = CGRectMake(frame.origin.x, frame.origin.y, frame.size.width-300, frame.size.height-100);

        _tbc = [[UITabBarController alloc] init];
        _tbc.viewControllers = @[[[MyTabBarViewController1 alloc] init],   [[MyTabBarViewController2 alloc] init]];
        //_tbc.view.backgroundColor = [UIColor blueColor];
        _tbc.view.autoresizesSubviews = YES;
        _tbc.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        _tbc.view.frame = smallFrame;

        [self.view addSubview:_tbc.view];
    }
}

MyViewController1 MyViewController2 - UIViewController, UILabel.

, UIViewController

@implementation MyTabBarAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.

    MyTabBarViewController *vc = [[MyTabBarViewController alloc] init];
    vc.view.backgroundColor = [UIColor yellowColor];
    vc.definesPresentationContext = NO;

    self.window.rootViewController = vc;
    [self.window makeKeyAndVisible];
    return YES;
}
+1

UITabBarController YES wantsFullScreenLayout, , , . , , .

wantsFullScreenLayout , , , .

0

Try this in a subclass of UITabBarController:

- (void)viewDidLoad {
    [super viewDidLoad];

    // A UITabBarController view has two subviews: the UITabBar and a container UITransitionView that is
    // used to hold the child views. Save a reference to the container.
    for (UIView *view in self.view.subviews) {
        if (![view isKindOfClass:[UITabBar class]]) {
            [view setFrame:RESIZED_FRAME];

        }
    }
}
0
source

All Articles