3

我們的iPad版本中存在下一個問題。iPad:UIModalPresentationFormSheet在橫向模式下失敗

我有一個UITabBar內的NavigationController。我想用一種看起來像&感覺與電子郵件形式相似的表單。

我使用相同的代碼,以顯示爲中心的模型:

// View to be displayed in the modal 
AdhocViewController *controller = [[AdhocViewController alloc] initWithNibName:@"AdhocViewController" bundle:[NSBundle mainBundle]]; 
controller.caller = self; 

// The form will need a navigation bar to cancel or save the form 
UINavigationController *modalViewNavController = [[UINavigationController alloc] 
               initWithRootViewController:controller]; 

// Configurate the modal presentation and transition 
modalViewNavController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
modalViewNavController.modalPresentationStyle = UIModalPresentationFormSheet; 

// Show the new view 
[self presentModalViewController:modalViewNavController animated:YES]; 

此代碼工作完全在縱向模式,但對景觀部分出現在屏幕的看法......我沒找到但解決它的方法。

我測試一些我發現這裏的解決方案......

並嘗試下一行預設的模型視圖來調整它之後添加,但不工作了

controller.view.superview.frame = CGRectMake(0, 0, 600, 700); 
controller.view.superview.center = self.view.center; 

有什麼建議嗎?

感謝,

伊萬

在StackOverflow的參考文獻:

+0

嘗試這樣的回答:http://stackoverflow.com/questions/4272718/modal-view-using-uimodalpresentationformsheet-appears-offscreen/4273720#4273720 – Anna

+0

我會盡力...的時刻,我修復了肖像模式 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { 回報(UIInterfaceOrientationIsPortrait(toInterfaceOrientation)); } –

+0

Karenina,我已經找到它並檢查它..但不成功...你能分享你準確的代碼嗎? 謝謝 –

回答

1

最後的代碼是下一個:

// Remove the modalTransitionStyle to enable the default behaviour and change to PageSheet 
modalViewNavController.modalPresentationStyle = UIModalPresentationPageSheet; 
// Present the modal view and adapt the center depending of the orientation 
[self presentModalViewController:modalViewNavController animated:YES]; 

UIDeviceOrientation _orientation = [controller interfaceOrientation]; 
if (UIDeviceOrientationIsPortrait(_orientation)){ 
    modalViewNavController.view.superview.center = CGPointMake(768/2, 1024/2 + 10); 
} else { 
    modalViewNavController.view.superview.center = CGPointMake(768/2 - 10, 1024/2); 
} 

的10和-10是因爲通過deafult模態的NavigationController是列於屏幕上方。

這是一個蹩腳的解決方案:SS但工程...雖然如果任何人有建議,很高興知道。

接縫,如果我需要包括相同的中心爲兩個方向,也許方向superview不是預期的。

在這個解決方案中,當我dissmiss上肖像取向的模態的視圖,至少在iPad模擬器,其旋轉到自動肖像模式...

最終溶液經主控制器執行presentModalViewController ,UITabBar,並更新解除方法以在其上執行。

[tabbar presentModalViewController:modalViewNavController animated:YES]; 

UIDeviceOrientation _orientation = [controller interfaceOrientation]; 
if (UIDeviceOrientationIsPortrait(_orientation)){ 
    modalViewNavController.view.superview.center = CGPointMake(768/2, 1024/2 + 10); 
} else { 
    modalViewNavController.view.superview.center = CGPointMake(1024/2, 768/2 + 10); 
} 

最後!!!!

謝謝

伊萬

5

隨着iOS7的關鍵是要設置modalTransitionStyle到UIModalTransitionCrossDissolve。

UIViewController *viewController = [[UIViewController alloc] init]; 
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController]; 

navigationController.modalPresentationStyle = UIModalPresentationFormSheet; 
navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; 

[self presentViewController:navigationController animated:YES completion:nil]; 
navigationController.view.superview.frame = CGRectMake(0, 0, 800, 544); 
navigationController.view.superview.center = self.view.center; 

https://coderwall.com/p/vebqaq

0

在iOS系統7,爲了解決模態視圖控制器的問題出現向左後幽靈鍵盤(問題,我有,當我在UIModalPresentationFormSheet呈現EKEventEditViewController,我:

[self presentViewController:modalViewController animated:YES completion:^{ 
    modalViewController.view.superview.center = self.view.center; 
}];