2015-02-11 31 views
4

我正在使用以下代碼以模態方式呈現視圖控制器。我已將演示文稿樣式更改爲「當前上下文」。它工作正常,在iOS 8,但屏幕變黑色OS < 8.我知道在當前上下文僅適用於iOS版8.我的問題是如何在iOS的7使用swift以編程方式在當前上下文中呈現視圖控制器

let vc = self.storyboard.instantiateViewControllerWithIdentifier("markerView") as! MarkerViewController 

self.presentViewController(vc, animated: false, completion: nil)

回答

9
實現這一目標

必須使用Current Context適用於iOS 7.

要檢查iOS版本,您可以使用NSFoundationVersionNumber

let iOS7 = floor(NSFoundationVersionNumber) <= floor(NSFoundationVersionNumber_iOS_7_1) 
let iOS8 = floor(NSFoundationVersionNumber) > floor(NSFoundationVersionNumber_iOS_7_1) 

然後你就可以檢查哪些版本正在運行,並使用OverCurrentContextCurrentContext

if iOS8 { 
    self.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext 
} else { 
    self.modalPresentationStyle = UIModalPresentationStyle.CurrentContext 
} 
+1

不適用於我。仍然在iOS 7屏幕上是黑色的。 – 2015-02-13 10:15:47

+2

在iOS7中,您必須在演示者上設置演示文稿樣式。 此外,這些iOS檢查似乎總是有問題,更新說到7.2會破壞這兩種情況。 – EricLeaf 2015-07-20 17:30:28

+0

偉大的提示,謝謝 – Fattie 2016-10-23 16:57:08

相關問題