简体   繁体   English

如何通过按下图像导航到另一个UIView控制器(以前在情节提要中创建)

[英]How to navigate to another UIView controller (previously created in storyboard) by pressing an image

I have created an image in my current story board and then I added the tap gesture to it so now once it's been tapped I know . 我在当前的故事板上创建了一个图像,然后向其添加了轻按手势,因此,一旦点击它,我就知道了。 Then I've created an other UIView controller in my story board which is connected to the cocatoch class called "DetailedUIViewController.swift" . 然后,我在故事板上创建了另一个UIView控制器,该控制器连接到名为“ DetailedUIViewController.swift”的cocatoch类。 Now I want to move to that view once I clicked on my image . 现在,我想在单击图像后移至该视图。

Here is my image : 这是我的形象:

@IBOutlet weak var totalEnergy: UIImageView!

and here is my tap gesture definition : 这是我的点击手势定义:

    let TGTE = UITapGestureRecognizer(target: self, action: #selector(totalEnergyFunc))
    totalEnergy.isUserInteractionEnabled = true
    TGTE.numberOfTapsRequired = 1
    totalEnergy.addGestureRecognizer(TGTE)

and here is the function that get called once I click on the image : 这是单击图像后调用的函数:

   func totalEnergyFunc(){

}

Now what I am trying to get is how to move to the second view which is previously created once my function get called ? 现在,我要获取的是如何转到调用函数后先前创建的第二个视图?

Make sure you have a storyboard ID for DetailedUIViewController 确保您具有DetailedUIViewControllerstoryboard ID

Press Command + Option + 3 and set storyboard ID for DetailedUIViewController 按Command + Option + 3并为DetailedUIViewController设置storyboard ID

故事板ID

Present DetailedUIViewController in totalEnergyFunc method totalEnergyFunc方法中显示DetailedUIViewController

func totalEnergyFunc(){
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "someViewController")
self.present(controller, animated: true, completion: nil)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从UIView导航到没有Storyboard和导航控制器的UIViewController - Navigate from UIView to UIViewController without storyboard and navigation controller 如何在Swift 4的视图控制器中的另一个uiview或图像上拖动多个uiview - How to drag multiple uiview on another uiview or image in a view controller in Swift 4 如何在不使用情节提要或IB的情况下从嵌入式集合视图的单元导航到另一个视图控制器? - How to navigate from an embedded collection view’s cell to another view controller without using Storyboard or IB? 如何从一个故事板导航到另一个 TabBarController? - How to navigate from one storyboard to another TabBarController? 如何使用Segues从UIView导航到UIView Controller? - How to navigate from UIView to a UIView Controller using segues? 如何在Ios中从一个项目情节提要导航到另一个项目情节提要 - How to navigate from one project storyboard to another project storyboard in Ios 如何将创建的视图控制器集成到情节提要中? - How to intergrate the created view controller into the storyboard? 如何修改故事板创建的视图控制器? - How to modify view controller created by storyboard? StoryBoard导航到Root View Controller - StoryBoard Navigate to Root View Controller 如何从通过情节提要创建的UITableView中拉出UIView? - How do I pull a UIView out of a UITableView created via storyboard?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM