繁体   English   中英

更改AppDelegate中设置的ViewController的框架

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

我正在使用控制器来代替传统的UITabBarController

我正在使用的是AKTabBarController 现在一切正常,但是有一个阶段我想使用手势将其删除。

手势是正确的,因为我刚刚删除了UINavigationBar 我可以指出的唯一区别是, UINavigationController是在相关的UIViewController中初始化的,而TabBar是在AppDelegate初始化的。

所以问题就在这里,我认为:

我似乎无法从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];
}

正如您在代码中看到的那样,我正在方法中初始化App Delegate,并且尝试访问tabBarController。 该代码不提供任何警告或错误,但在应用程序运行时不起作用。

我不确定是否需要做其他事情,因为它是一个自定义控件。 同样,此控件是从UIViewController而不是UITabBarController继承的。

它在应用程序委托中的以下行中添加到项目中: [_window setRootViewController:_tabBarController];

让我知道是否需要提供更多详细信息,但是我在这里有点迷失了。

您正在以错误的方式创建AppDelegate实例,将其替换为以下内容:

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

希望它会帮助你。

-(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];
}

试试这个可能会帮助您.....

暂无
暂无

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

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