开发者

ViewController view starts with at ~(0,20)

I've tried starting view based app and window based app but I still have the same problem. When I add a navigation bar it looks like it starts at cords ~(0,20) and leaves some space between the it and the "system tray" (i can't find the word for the dock with clock and batteri etc.)

i can't figure out why this occurs because the nslog of frame tells me that it origins in (0,0) (and strangely the width is 0 :/ but it is clearly visible).

code:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        UIImageView *image = [[UIImageView alloc] initWithFrame:CGR开发者_开发知识库ectMake(self.view.frame.origin.x, 
                                                                       self.view.frame.origin.y+48.0f, 
                                                                       self.view.frame.size.width, 
                                                                       self.view.frame.size.height)];
        [image setImage:[UIImage imageNamed:@"IMG_0792.PNG"]];
        [self.view addSubview:image];

        self.navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(self.view.frame.origin.x, 
                                                                    self.view.frame.origin.y, 
                                                                    self.view.frame.size.width, 
                                                                    45.0f)];

        [navBar setDelegate:self];    
        [navBar pushNavigationItem: [[UINavigationItem alloc] initWithTitle:@"Image Stream"] animated:NO];
        [self.view addSubview:navBar];
    }
    return self;
}

and in the appdelegate i just declare it, retain-property and:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.menu = [[MenuViewController alloc] initWithNibName:nil bundle:nil];
    [self.window setRootViewController:menu];
    [self.window makeKeyAndVisible];
    return YES;
}

would be very nice if someone knew why this happens. thanks


When positioning a view using the coordinates of the superview, use bounds, not frame. If there's a status bar, your superview.frame.x will be non-zero, but the subview's coordinates are relative to the superview, not the position.


Check the following:

  • In your UIViewController's Xib if it has status bar. If yes, then put None. (You can set that in the inspector, just select your root UIView.

  • Are you adding your UIViewController to your App delegate's by XIB? If yes, go check in the App's delegate xib your UIViewController and see if it has status bar.

p.s: its called status bar.

Edit what about the frame you use for your UINavigation? The 45.0f.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜