![](/img/trans.png)
[英]How to pass an image from one viewcontroller to another viewcontroller in swift?
[英]How to open next viewcontroller after choosing image from gallery (swift)
您可以使用 Interface Builder 或在代碼中(根據需要)將UITapGestureRecognizer
放入您的UIImageView
,我更喜歡第一個。 您可以在UIImageView
放置一個@IBAction
並處理點擊,不要忘記在 Interface Builder 或代碼中將UserInteractionEnabled
設置為true
。
要呈現下一個視圖控制器,您可以在如下代碼中執行此操作,也可以通過之前設置的UITapGestureRecognizer
使用UITapGestureRecognizer
使用 Interface Builder(這取決於您)。
要像以下代碼一樣手動顯示視圖控制器,您需要為您的視圖控制器設置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)
}
我希望這對你有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.