2011-06-08 77 views
1

我正在開發支持橫向和縱向orientation.I兩個不同的筆尖文件爲我的rootviewController iPad應用程序。以下是該問題的場景 -
1.在portait模式下從根視圖中選擇一個項目,以縱向推送下一個視圖。
2.轉動設備
3.按導航欄上的後退按鈕
該視圖從堆棧加載的是rootViewController的portait視圖。設備仍處於橫向模式。
請建議解決方案來處理上述問題。
另外,請在處理設備旋轉時建議遵循的最佳做法。UINavigationController在橫向和縱向模式下導航的最佳做法

回答

1

以下列方法使用通知,並設置receivedRotate方法中的座標。

-(void)viewWillAppear:(BOOL)animated 
{ 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedRotate:) name:UIDeviceOrientationDidChangeNotification object:nil]; 
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 

} 

-(void)viewWillDisappear:(BOOL)animated 
{ 
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil]; 
} 

例如在receivedRotate你可以設置你的tableview的座標爲:

if (orientation == UIDeviceOrientationLandscapeLeft||orientation==UIDeviceOrientationLandscapeRight) 
    { 
     [tblView reloadData]; 
     tableX=70.0; 

    } 
    else 
    { 
     [tblView reloadData]; 
     tableX=48.0; 
} 

也叫recieveRotate在viewDidLoad中這是非常重要

+0

感謝nitish的詳細答案。它類似於iAmitwagh精神超過 – amavi 2011-06-08 11:31:31

+1

是的。但我之前發佈它:) – Nitish 2011-06-08 11:33:37

1

檢查這種方法,可能會幫助ü...

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
// Return YES for supported orientations. 
return ( 
     interfaceOrientation == UIInterfaceOrientationPortrait 
     || interfaceOrientation == UIInterfaceOrientationLandscapeLeft 
     || interfaceOrientation == UIInterfaceOrientationLandscapeRight 
     || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown 
     );} 

或嘗試設置autoresizingMask的控制器希望這將有助於ü。

+0

我回來是支持所有的旋轉。你可以把一些光autoresizingMask?如何以及在哪裏設置? – amavi 2011-06-08 09:56:27

+0

其UIComponent的屬性。你可以將它設置爲UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight。它會根據方向自動調整UI組件的寬度和高度。 – 2011-06-08 09:58:48

1

您需要在運行時方法 檢查方向 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

} &變化根據定向視圖的元素。

+0

感謝Amit.It協同實現 - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation持續時間:(NSTimeInterval)持續時間方法來處理旋轉。 – amavi 2011-06-08 11:30:47

相關問題