简体   繁体   English

更改AppDelegate中设置的ViewController的框架

[英]Change the frame of a ViewController set in AppDelegate

I am using a controller to replace the traditional UITabBarController . 我正在使用控制器来代替传统的UITabBarController

The one I am using is AKTabBarController . 我正在使用的是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. 手势是正确的,因为我刚刚删除了UINavigationBar 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 . 我可以指出的唯一区别是, UINavigationController是在相关的UIViewController中初始化的,而TabBar是在AppDelegate初始化的。

So the problem lies here I think: 所以问题就在这里,我认为:

I cannot seem to manipulate the frame of the TabBarController from the ViewController. 我似乎无法从ViewController操纵TabBarController的框架。

-(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. 正如您在代码中看到的那样,我正在方法中初始化App Delegate,并且尝试访问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. 同样,此控件是从UIViewController而不是UITabBarController继承的。

It is added to the project with this line in the app delegate: [_window setRootViewController:_tabBarController]; 它在应用程序委托中的以下行中添加到项目中: [_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 :- 您正在以错误的方式创建AppDelegate实例,将其替换为以下内容:

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..... 试试这个可能会帮助您.....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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