按下时,ViewController从屏幕下部留下20px白色 [英] ViewController is leaving 20px white from lower part of screen when pushed

查看:47
本文介绍了按下时,ViewController从屏幕下部留下20px白色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在应用程序委托中启动应用程序期间,我正在使用多个控制器.一个控制器用于注册,第二个控制器用于标签栏.标签栏加载正常,但是当我在窗口上按下注册控制器时,内容增加了20个单位,并且底部有白色的空白屏幕.因此,我以其viewdidload方法重新创建了注册视图控制器的框架,并将其向下滑动了20个单位.代码是

I am using multiple controller during launch of an application in app delegate. One controller is for registration and the second controller is tabbar. tabbar was loading fine but when I pushed registration controller on window, contents went up by 20 units and I have good white blank screen at bottom. Therefore I recreated frame of my registration view controller in its viewdidload method and slided it 20 units down. The code is

self.view.frame = CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height);

,我的启动委托中的应用程序委托中的代码为

and code in my app delegate for launch application was

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    if (![self accountExists]) {
                //code if account does not exists on iphone app database
        self.registerAccount = [[registerViewController alloc] initWithNibName:@"registerViewController" bundle:nil];
        [window addSubview:registerAccount.view];
    }
    else if([self autoLoginForAnyAccount]){
        //code for autologin to app
    }
    else {
        self.tabBarController.selectedIndex = 1;
        self.tabBarController.delegate = self;
        [window addSubview:tabBarController.view];
    }
    [window makeKeyAndVisible];
    return YES;
}

如果有人知道按下注册控制器时底部为什么会有空白,请与我分享.

if anyone knows why there is a white space at bottom when registration controller is pushed then please share it with me.

推荐答案

我知道了问题所在,但没有找到原因.问题是窗口的大小,即在我的代码中我正在创建registerViewController的实例,因此它的大小是窗口的大小减去状态栏的大小(因为它是必须显示在状态栏下方的视图控制器).当我将registerViewController推到窗口上时,由于某种原因(我不知道为什么),视图控制器无法识别标题中的状态栏,而registerViewController的20px显示在状态栏后面.然后我尝试了代码registerAccount.view.frame = window.frame;,该代码将我的注册控制器的帧设置为等于窗口控制器.这删除了底部的空白屏幕,现在视图占据了整个窗口的大小,但是状态栏后面仍然有20px,因为我的视图控制器看不到状态栏的存在.我尝试使用在屏幕上显示我的整个控制器的代码删除状态栏,但我也想在顶部显示状态栏.

I figure out the issue but not the reason. Issue was size of the window i.e. In my code i was creating instance of registerViewController therefore its size was size of the window minus size of the status bar(since it is a view controller which must be displayed below status bar). When i pushed registerViewController onto window then because of some reason (i dont know why) view controller failed to recognize status bar in the header and 20px of registerViewController was displaying behind status bar. then I tried code registerAccount.view.frame = window.frame; which sets the frame of my registration controller equals to window controller. This removed blank white screen at the bottom and view now taking whole of the window size but still 20px was behind status bar since my view controller was blind to see existance of status bar. I tried to remove status bar using code which showed my whole controller on the screen but I wanted status bar at the top too.

我通过在mainWindow.xib文件中添加UIViewcontroller对象(就像我的标签栏控制器一样)来找出方法,并指出其类为registerViewController并加载了registerViewController的笔尖.我还删除了self.registerAccount = [[registerViewController alloc] initWithNibName:@"registerViewController" bundle:nil];

I figure out my way by adding UIViewcontroller object in my mainWindow.xib file(just like my tab bar controller) and I pointed its class to be registerViewController and loaded nib of registerViewController. i also removed line self.registerAccount = [[registerViewController alloc] initWithNibName:@"registerViewController" bundle:nil];

,然后在我的代理.h文件registerViewController *registerAccount;中将其替换为UIViewController *registerAccount;,在mainWindow.xib文件中,我将新添加的视图控制器指向了该控制器.现在一切正常,但是我仍然不知道为什么当我推送registerViewController的实例时,viewcontroller为什么看不到状态栏. 如果有人知道原因,请与我分享.

and replaced in my delegate .h file registerViewController *registerAccount; with UIViewController *registerAccount; and in mainWindow.xib file I pointed my newly added view controller to this controller. Now everthing is working fine but I still dont know why viewcontroller failed to see status bar when I pushed instance of registerViewController. if anyone knows the reason then please share here with me.

这篇关于按下时,ViewController从屏幕下部留下20px白色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆