ios - 使用 Swift 打开新的 UIViewController

标签 ios iphone swift events uiviewcontroller

使用 CoreGraphics,我可以获得点击位置。

我的要求是根据对图像不同区域的点击打开不同的 UIViewController

最佳答案

您需要使用以下方法之一根据触摸位置创建一个新的 UIViewController:

  1. 手动创建

    let controller = SubclassViewController()
    //prepare your view controller here
    
  2. 从 Storyboard实例化 Controller

    if let controller = storyboard.instantiateViewControllerWithIdentifier("identifier") as? SubclassViewController {
        //prepare your view controller here
    }
    
  3. 执行 segue 到新的 View Controller

    performSegueWithIdentifier("segueIdentifier")
    

    然后在 prepareForSegue: 中准备你的 View Controller

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

根据您的应用正在执行的操作,您可以推送新的 View Controller 或手动呈现它

关于ios - 使用 Swift 打开新的 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33580286/

相关文章:

ios - UITextContainerView 不调整大小作为他的 UITextView superview,仅当旋转角度大于 45°

ios - 如何在 iphone 中访问动态创建的 uilabel

swift - 类如何符合具有协议(protocol)约束关联类型的协议(protocol)?

Swift 2 print(),如何隐藏?

Swift Playground - 如何将带逗号的字符串转换为带小数的字符串

iOS 8.0 模拟器通过 HTTPS 而不是 HTTP 打开连接

ios - UIDatePicker:为时间添加约束

iphone - PST 中所需的 NSDate

iphone - UIImageView 在我的 UINavigationBar 下面是 "squished"

iphone - 为什么 Wingdings 在 iOS 5 上无法运行?为什么我无法在 iPhone 应用程序中使用 Wingdings?