开发者

Why do navigation appear 20 pixels below status bar in the view? [duplicate]

开发者 https://www.devze.com 2023-03-01 17:55 出处:网络
This question already has answers here: Closed 10 years ago. Possible Duplicate: UIWebView on iPad size - (void)viewDidLoad {
This question already has answers here: Closed 10 years ago.

Possible Duplicate:

UIWebView on iPad size

- (void)viewDidLoad {

    [super viewDidLoad开发者_JAVA百科];

    UINavigationController *naviController = [[UINavigationController alloc]init];

    [self.view addSubview:naviController.view];

}

If I add navigation controller in the view, it appears about 20 pixels below status bar. I want it appears just below status bar. How do I fix this?


I've experienced this same issue.

This discussion was helpful: UIWebView on iPad size

Tony's answer helped me discover this trick:

naviController.view.frame = self.view.bounds;


Turns out setting the view height fixes this problem. You can do it in the nib (xib) file or progammatically when creating the view setting the view.frame = CGRect(0, 0, 320.0 460.0); or whatever it's supposed to be (in your case it looks like it should be 460.0 since you have the status bar on).

The main point is that if the view size is smaller than the height of the screen, there are no guarantees where your controls will show up.


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    CGRect frame = CGRectMake(0, 0, 320.0, 480.0);
    viewController.view.frame = frame;
    [self.window addSubview:viewController.view];
    [self.window makeKeyAndVisible];

    return YES;
}

I changed like above. It works. So far so good. If height was 460, there would have been blank line at the bottom. View's absolute coordinate is (0, 20). So, Navigation bar's coordinate is (0, 40). I think that was the problem. I will encounter another problem. Maybe there is way to change coordinate before displaying navigation view. Thank you.

0

精彩评论

暂无评论...
验证码 换一张
取 消