I'm new to IOS and learning the IDE at the moment. I was wondering if its possible to link an imageView, when clicked, to a View Controller
- 
                    1Pls take a look at https://stackoverflow.com/questions/36277208/swift-2-click-on-image-to-load-a-new-viewcontroller coz it is quite similar. gl – yveszenne May 08 '18 at 14:49
5 Answers
Sure. First, in viewDidLoad of your UIViewController make it tappable:
imageView.isUserInteractionEnabled = true
Then assign the gesture recognizer:
imageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.imageTap)))
Once the action is triggered, perform a transition to a new VC:
// Func in your UIViewController
@objc func imageTap() {
    // present modally
    self.present(YourNewViewController())
    // or push to the navigation stack
    self.navigationController?.push(YourNewViewController())
    // or perform segue if you use storyboards
    self.preformSegue(...)
}
 
    
    - 1,177
- 8
- 17
Yes. It is possible. You'll need to add a tap gesture recogniser to image view and in the function perform segue.
SWIFT 4
let singleTap = UITapGestureRecognizer(target: self,action:Selector(“imageTapped”))
yourImageView.isUserInteractionEnabled = true
yourImageView.addGestureRecognizer(singleTap)
Function to handle Tap:
@objc func imageTapped() {
    performSegue(withIdentifier: "yourNextScreen", sender: "")
}
 
    
    - 259
- 3
- 10
Yes. You can bind a tap gesture recognizer to your imageview. You can follow this link here on a previous answer on how to do it programmatically
You could do it completely in the interface builder by putting a UIButton, with a transparent background and no text, over the ImageView and then control drag the button to the viewcontroller you want to trigger a segue on touch.
 
    
    - 116
- 5
Of course it is. You should add a UITapGestureRecognizer to the UIImageView and add a selector to trigger the pushing a new viewcontroller method.
For example;
@IBOutlet weak var imageView: UIImageView! {
    didSet {
        let imageTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(imageTapped))
        imageView.addGestureRecognizer(imageTapGestureRecognizer)
        imageView.isUserInteractionEnabled = true
    }
}
func imageTapped() {
    //navigate to another view controller
}
 
    
    - 447
- 7
- 13
- 
                    ok would i add the view controller method within the selector or in a func where the image is clicked – Vanoshan Ramdhani May 08 '18 at 14:45
- 
                    
 
    