开发者

iPhone UI Design for Navigation Controller - buttons moving down

I created a navigation controller based app. The view that opens up below the nvigation bar has a UIImageView and a bunch of 'detail disclosure' buttons on top of te uiimage for navigation purposes as well.

What I am noticing is that these buttons s have deviated down from their designer (interface builder) position when they come up in the simulator.

I suspect the navigation bar has something to do with it, but they don't move down proportional to the height of the navigation bar.

I am not sure how to tell them to hold on to their position.

The UIImage does not overflow the height of the screen even with the navigaion bar at the top.

Are their any guidelines/gotchas one needs to know about when using navigation bar at the top?

I am using xcode 4

Thanks

Edit:

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

    StartScreenViewController *controller = 
    [[StartScreenViewController alloc] initWithNibName:@"StartScreenViewController" bundle:nil];
    _navigationController = [[UINavigationController alloc] initWithRootViewController:controller];

    _navigationController.view.frame = CGRectMake(0,0, 320, 460);
    _navigationController.title = @"Test";
    //[self.window addSubview:_navigationController.view];

    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];
    return YES;
}

Another thing is that if I use the 'addsubview' method then the nav bar is truncated while if I assign the nav controller to window.rootviewcontroller then I see the whole nav bar.

Edit 2

Here how my AppDelegate.h looks

@interface TestAppDelegate : NSObj开发者_开发技巧ect <UIApplicationDelegate> {

    IBOutlet UIView *mainView;
}

@property (nonatomic, retain) IBOutlet UIView *mainView;

@property (nonatomic, retain) IBOutlet UIWindow *window;

//@property (nonatomic, retain) IBOutlet UIViewController *viewController;

@end

Here is the AppDelegate.m's didFinishLaunchingWithOptions method

StartScreenViewController *controller = [[StartScreenViewController alloc] initWithNibName:@"StartScreenViewController" bundle:nil];
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
    navController.title = @"Test";
    navController.view.frame = CGRectMake(0, 0, 320, 460);
    [self.mainView addSubview:navController.view];    
    [self.window makeKeyAndVisible];

The MainWindow.xib contains App delegate and the window as the objects. the Window has a UIView underneath it.

StartScreenViewcontroller's xib file has the UIImageview and the buttons.


Take some screen shots and see how far they are being moved down. If its 20px then this is a problem that tons of people have had (including myself). I fixed it by redefining the view to be the same size that it is in IB. For some reason the iPhone tries to be smart and help you resize things and sometimes it does it wrong.

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
                navController.view.frame = CGRectMake(0, 0, 320, 460);
[self.window addSubview:navController.view];

If that doesn't work then try this search: https://stackoverflow.com/search?q=%5Biphone%5D+20px.


EDIT:
I missed a piece here. In order to get around this I had to add a UIView to the MainWindow.xib file....

1. In your AppDelegate.h, create a property for IBOutlet UIView *mainView
2. Do the @property thing for it and synthesize it in the .m file
3. Open MainWindow.xib
4. Drag a UIView onto the Window (NOT the ViewController) and make it fit the full frame
5. Right click the AppDelegate object in the Documents window in IB and connect the mainView property to the UIView you just added.
6. Now in AppDelegate.m...

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

    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
    navController.view.frame = CGRectMake(0, 0, 320, 460);

    //[self.window addSubview:navController.view]; // old broken way
    [mainView addSubview:navController.view];
    [self.window makeKeyAndVisible];

    return YES;
}

and AppDelegate.h:

@interface TestNavigationAppAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    TestNavigationAppViewController *viewController;
    IBOutlet UIView *mainView;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet TestNavigationAppViewController *viewController;
@property (nonatomic, retain) IBOutlet UIView *mainView;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜