简体   繁体   English

从图库中选择图像后如何打开下一个视图控制器(swift)

[英]How to open next viewcontroller after choosing image from gallery (swift)

I am trying to open next viewController after choosing photo from gallery.从图库中选择照片后,我试图打开下一个 viewController。 I can get image from gallery, but after that I dont know how to open controller next to it.我可以从图库中获取图像,但之后我不知道如何打开它旁边的控制器。 !. !。 This is photo of that storyboard这是那个故事板的照片

You can put an UITapGestureRecognizer inside your UIImageView using Interface Builder or in code (as you want), I prefer the first.您可以使用 Interface Builder 或在代码中(根据需要)将UITapGestureRecognizer放入您的UIImageView ,我更喜欢第一个。 The you can put an @IBAction and handle the tap inside your UIImageView , Don't forget to set the UserInteractionEnabled to true in Interface Builder or in code.您可以在UIImageView放置一个@IBAction并处理点击,不要忘记在 Interface Builder 或代码中将UserInteractionEnabled设置为true

To present the next view controller you can do it in code like below or just using Interface Builder using a segue through the UITapGestureRecognizer you set before (it's up to you).要呈现下一个视图控制器,您可以在如下代码中执行此操作,也可以通过之前设置的UITapGestureRecognizer使用UITapGestureRecognizer使用 Interface Builder(这取决于您)。

To present the view controller manually like in the following code you need to set the Storyboard ID for you view controller like in the following picture (in the Identity Inspector panel ):要像以下代码一样手动显示视图控制器,您需要为您的视图控制器设置Storyboard ID ,如下图所示(在Identity Inspector 面板中):

在此处输入图片说明

@IBAction func imageTapped(sender: AnyObject) {

    // Set the storyboard name by default is Main
    let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil)

    // Instantiate the ViewController with the name you set before like in the image
    let nextViewController = storyboard.instantiateViewControllerWithIdentifier("ViewControllerB") as! UIViewController

    // present the nextViewController
    self.presentViewController(nextViewController, animated: true, completion: nil)
}

I hope this help you.我希望这对你有帮助。

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

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