我创建了一个基于导航控制器的应用程序。在NVigation Bar下方打开的视图具有UIImageView和一堆在TE UiImage上的按钮,用于导航目的。

我注意到这些按钮S已经偏离了他们的设计者(接口构建器)位置时偏离了模拟器。

我怀疑导航栏与它有关,但它们不会与导航栏的高度成比例。

我不确定如何告诉他们坚持自己的位置。

UIImage即使在顶部的Navigaion栏也不会溢出屏幕的高度。

是他们在顶部使用导航栏时需要了解的任何准则/ GOTCHAS?

我正在使用Xcode 4

感谢

编辑:

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

另一件事是,如果我使用'addsubview'方法,那么如果我将NAV控制器分配给Window.RootViewController,则截断NAV栏,然后我看到整个导航栏。

编辑2

这里我的appdelegate.h看起来

@interface TestAppDelegate : NSObject <UIApplicationDelegate> {

    IBOutlet UIView *mainView;
}

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

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

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

@end
.

这里是appdelegate.m的didfinishlaunchingwithoptions方法

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];
.

mainwindow.xib包含应用程序委托和窗口作为对象。窗口在它下面有一个UIView。

startscreenViewController的XIB文件具有UIImageView和按钮。

有帮助吗?

解决方案

拍摄一些屏幕镜头,看看它们被移动了多远。如果它的20px那么这是一个有吨的问题(包括我自己)。通过重新定义视图与IB中的大小相同,我修复了它。由于某种原因,iPhone试图聪明,并帮助您调整内容,有时它会产生错误。

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

如果它不起作用,请尝试此搜索: https://stackoverflow.com/search?q=%5biphone%5d + 20px

编辑:
我在这里错过了一块。为了解决这个问题,我必须将UIView添加到MainWindow.xib文件....

1.在您的AppDelegate.h中,为iboutlet uiview * mainview创建一个属性 2.做@Property的事情,并在.m文件中综合它 3.打开MainWindow.xib
4.将UIView拖到窗口(不是ViewController)上,并使其适合全帧

5.右键单击IB中“文档”窗口中的AppDelegate对象,将MainView属性连接到您刚添加的UIView。
6.现在在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;
}
.

和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;
.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top