Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Present view controller modally over current context programmatically using swift

Tags:

ios

swift

I am using following code to present a view controller modally. I have changed presentation style to "Over current Context". It works fine on iOS 8 but screen gets black on os < 8. I know Over Current Context is available only in iOS 8. My question is how can I achieve this in iOS 7.

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

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

like image 443
Saqib Omer Avatar asked Feb 11 '15 10:02

Saqib Omer


People also ask

How do you dismiss the current view controller and go to another view in Swift?

This second controller has a dismiss option that just comes back to the root view controller and a button that when the user touches it dismisses the current view controller so it goes back to the root view controller for a second and presents another one.


1 Answers

You have to use Current Context for iOS 7.

To check the iOS-Version you can use NSFoundationVersionNumber.

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

Then you can check which version is running and use OverCurrentContext or CurrentContext.

if iOS8 {
  self.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext
} else {
  self.modalPresentationStyle = UIModalPresentationStyle.CurrentContext
}
like image 184
Christian Avatar answered Sep 17 '22 13:09

Christian