2013-07-24 39 views
0

我正在構建一個模板應用程序。我在設備旋轉/方向上遇到了一些問題。我在我的appDelegate didFinishLaunching如下:Objective-c設備方向

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 

,並在我的VC viewDidLoad中:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil]; 

...

//add the title bar 
    titleBar = [[OAI_TitleBar alloc] initWithFrame:CGRectMake(0.0, 0.0, 1024.0, 50.0)]; 
    titleBar.titleBarTitle = @"OAI Template"; 
    titleBar.hasAccount = YES; 
    titleBar.hasReset = YES; 
    titleBar.hasHome = YES; 
    [titleBar buildTitleBar]; 
    [self.view addSubview:titleBar]; 

這是我deviceOrientationDidChange方法:

//rotate the vc view 
    if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)) { 
     [self.view setFrame:CGRectMake(0.0, 0.0, 1024.0, 768.0)]; 

    } else if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)) { 

     [self.view setFrame:CGRectMake(0.0, 0.0, 768.0, 1024.0)]; 
    } 

    //call the rotation management methods of various classes 
    [titleBar adjustForRotation:orientation]; 

}

這工作正常,當我旋轉設備,意見調整如預期。但是當應用程序啓動時,x,y座標是錯誤的 - 當我以縱向方式啓動時記錄框架時,VC視圖的框架爲{{0,20},{768,1004}},當以橫向模式啓動時{{20,0},{748,1024}}

橫向和縱向標題欄框架{{20,0},{748,1024}}(與我編碼時一樣)。

但是,我在模擬器和我的設備上看到的是截然不同的。你應該看到的是一個黑色的條(頂部有50個像素左右),左邊有一個標誌,隨後是一些按鈕,然後應用標題向右對齊。正如你可以從下面的圖片看到的,當應用程序以任一方向啓動時,它的開放x/y座標不會在0/20附近。任何幫助,將不勝感激。

看起來對我來說,當應用程序在橫向上啓動時,它將顯示爲縱向,當它以縱向顯示時,儘管顯示是正確的,但大約在20.0f左右。任何幫助,將不勝感激。

Landscape screen capture

Portrait screen capture

+0

好吧,所以肖像解決方案很明顯,它應該重置爲0,20,1004,768,但我仍然有景觀視圖的問題,雖然我現在可以看到一個標題欄,VC視圖本身是從設備的左側邊緣加載約200.0英寸的內容。 – PruitIgoe

回答

0

解決它,我

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 

    return interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight; 
} 
在我的viewController

,確信正確的方向在我的plist和它加載的罰款。