简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM