简体   繁体   中英

Change the frame of a ViewController set in AppDelegate

I am using a controller to replace the traditional UITabBarController .

The one I am using is AKTabBarController . Now All is working, but there is one stage where I want to remove it using a Gesture.

The gesture is correct since I am removing the UINavigationBar just fine. The only difference I can point out is that the UINavigationController is initiated within the relevant UIViewController and the TabBar is initialized in the AppDelegate .

So the problem lies here I think:

I cannot seem to manipulate the frame of the TabBarController from the ViewController.

-(void)goFull
{
    JWKAppDelegate *appdel = [[JWKAppDelegate alloc] init];

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];

    self.webView.frame = CGRectMake(0, 0, 320, 411); // (00,00 : -20, -94)
    _navBar.frame = CGRectMake(0, 0, 320, 0);
    appdel.tabBarController.view.frame = CGRectMake(0, 0, 320, 0);

    NSLog(@"My view frame: %@", NSStringFromCGRect(appdel.tabBarController.view.frame));

    [UIView commitAnimations];
}

As you can see in the code I am initializing the App Delegate in the method and I am trying to access the tabBarController. This code provides no warnings or errors, but somehow does not work when the app is running.

I am not sure if I need to do something else, because it is a custom control. Also this control is subclassed from a UIViewController not a UITabBarController.

It is added to the project with this line in the app delegate: [_window setRootViewController:_tabBarController];

Let me know if I need to provide any more details, but I am a bit lost here.

You are creating the instance of AppDelegate in a wrong way , replace it with the following :-

JWKAppDelegate *appdel = (JWKAppDelegate  *)[[UIApplication sharedApplication] delegate];

Hope it will help you.

-(void)goFull
{

 JWKAppDelegate *appdel = (JWKAppDelegate  *)[[UIApplication sharedApplication] delegate];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];

self.webView.frame = CGRectMake(0, 0, 320, 411); // (00,00 : -20, -94)
_navBar.frame = CGRectMake(0, 0, 320, 0);
appdel.tabBarController.view.frame = CGRectMake(0, 0, 320, 0);

NSLog(@"My view frame: %@", NSStringFromCGRect(appdel.tabBarController.view.frame));

[UIView commitAnimations];
}

Try this it may help you.....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM