sau123
sau123

Reputation: 352

Open new UIViewController using Swift

Using CoreGraphics, I am able to get click location.

My requirement is to open different UIViewController base on clicks on different areas of an image.

Upvotes: 1

Views: 120

Answers (1)

Bartłomiej Semańczyk
Bartłomiej Semańczyk

Reputation: 61774

You need to create a new UIViewController base on location of your touch using one of the following:

  1. Create it manually

    let controller = SubclassViewController()
    //prepare your view controller here
    
  2. Instantiate controller from storyboard

    if let controller = storyboard.instantiateViewControllerWithIdentifier("identifier") as? SubclassViewController {
        //prepare your view controller here
    }
    
  3. Perform segue to new view controller

    performSegueWithIdentifier("segueIdentifier")
    

    Then prepare your view controller within prepareForSegue:

    if let controller = segue.destinationViewController as? SubclassViewController {
        //prepare your controller here
    }
    

Depending on what your app is doing, you can either to push your new view controller or present it manually

Upvotes: 1

Related Questions