2014-01-20 72 views
0

我試圖爲我的應用程序的不同子模式實施強制肖像/風景取向。爲此,我有一個UINavigationController作爲根控制器和每個子模式具有它是是iPhone視圖控制器風景/肖像旋轉問題

@interface iosPortraitViewController : UIViewController 

@interface iosLandscapeViewController : UIViewController 

與任一

-(BOOL)shouldAutorotate; 
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation; 
-(NSUInteger) supportedInterfaceOrientations; 

重載一個和自己的視圖控制器根據每個人的方向類型正確設置。例如iosLandscapeViewController :: supportedInterfaceOrientations返回UIInterfaceOrientationMaskLandscape。

當應用程序中的子模式發生變化時,相應的視圖控制器將使用present/dismissViewController呈現在根視圖控制器上,並強制重定向並調用重載視圖控制器類中的函數並定位自身因此。

我的問題是,當我們切換到橫向時,子模式視圖的框架從它應該在的屏幕的左上角偏移(它是顯示背景圖片的全屏視圖)。

爲了進行調試,如果我改變該子模式視圖控制器到iosPortraitViewController視圖的信息是:

size = 480.000000 320.000000 
bounds = 0.000000 0.000000 480.000000 320.000000 
frame = 0.000000 0.000000 480.000000 320.000000 
centre = 240.000000 160.000000 
user interaction enabled = 1 
hidden = 0 
transform = 1.000000 0.000000 0.000000 1.000000 : 0.000000 0.000000 

當在橫向模式,這是它需要的視圖信息:

size = 480.000000 320.000000 
bounds = 0.000000 0.000000 480.000000 320.000000 
frame = 80.000000 -80.000000 320.000000 480.000000 
centre = 240.000000 160.000000 
user interaction enabled = 1 
hidden = 0 
transform = 0.000000 -1.000000 1.000000 0.000000 : 0.000000 0.000000 

80,-80起源框架的是我遇到的問題 - 它應該是0,0。 (如果任何人都可以指出它是如何得到80,-80也是值得讚賞的 - 我可以看到它的X,但不是Y)。

另請注意,框架中的w和h如何交換,變換是旋轉變換 - 從閱讀中,我猜UIWindow(它始終處於縱向模式)已將此應用於視圖變換根視圖控制器?

我能做些什麼來解決這個問題?我需要視圖控制器視圖的框架位於正確的位置(即原點爲0,0)。我嘗試了對它進行硬編碼,但它似乎沒有工作,反正它不是一個很好的解決方案 - 我非常理解正在發生的事情以及如何正確解決它。

謝謝!

:-)

回答

1

爲了支持備用景觀界面,你必須做到以下幾點:

  1. 實現兩個視圖控制器對象。一個呈現僅肖像界面,另一個呈現僅景觀界面。
  2. 註冊UIDeviceOrientationDidChangeNotification通知。在您的處理程序方法中,根據當前設備方向呈現或取消備用視圖控制器。

從蘋果公司的指導Creating an Alternate Landscape Interface

從導

另外:

@implementation PortraitViewController 
- (void)awakeFromNib 
{ 
    isShowingLandscapeView = NO; 
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
    [[NSNotificationCenter defaultCenter] addObserver:self 
           selector:@selector(orientationChanged:) 
           name:UIDeviceOrientationDidChangeNotification 
           object:nil]; 
} 

- (void)orientationChanged:(NSNotification *)notification 
{ 
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation; 
    if (UIDeviceOrientationIsLandscape(deviceOrientation) && 
     !isShowingLandscapeView) 
    { 
     [self performSegueWithIdentifier:@"DisplayAlternateView" sender:self]; 
     isShowingLandscapeView = YES; 
    } 
    else if (UIDeviceOrientationIsPortrait(deviceOrientation) && 
      isShowingLandscapeView) 
    { 
     [self dismissViewControllerAnimated:YES completion:nil]; 
     isShowingLandscapeView = NO; 
    } 
} 
相關問題