開頭我已經嘗試開始基於視圖的應用程序和基於窗口的應用程序,但我仍然有同樣的問題。 當我添加一個導航欄時,它看起來像從〜(0,20)的繩索開始,並在它和「系統托盤」之間留下一些空間(我找不到與時鐘和電池等相關的字。 )ViewController視圖以〜(0,20)
我不明白爲什麼會出現這種情況,因爲nslog幀告訴我它起源於(0,0)(奇怪的是寬度爲0:/但它清晰可見)。
代碼:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(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;
}
,並在我的appdelegate聲明即可,保留屬性和:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.menu = [[MenuViewController alloc] initWithNibName:nil bundle:nil];
[self.window setRootViewController:menu];
[self.window makeKeyAndVisible];
return YES;
}
將是非常好的,如果有人知道爲什麼會這樣。感謝
謝謝@joerick那個伎倆:) –