How to implement isUserInteractionEnabled

I want to enable the UIView Image for gestures and touch events.

The provided code for this is in the docs, but how do you use it?


var isUserInteractionEnabled: Bool { get set }

https://developer.apple.com/documentation/uikit/uiimageview/1621063-isuserinteractionenabled

If you mean var isUserInteractionEnabled: Bool { get set } as the provided code, it is not something to use, but to understand what it is. It explains that isUserInteractionEnabled is a read-write property of type Bool.


To use isUserInteractionEnabled, you may need to write something like this:

import UIKit

class ViewController: UIViewController {
    
    @IBOutlet var imageView: UIImageView!
    //...

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        imageView.isUserInteractionEnabled = true
        //...
    }

    //...
}

You should better show your code when you ask something, that explains how experienced you are and helps getting better answers which will fit for your code.


And to make a good communication in the forums, you should better reply to answers or comments to your posts.

You can also enable interaction directly in Interface Builder, with the Attributes Inspector.

How to implement isUserInteractionEnabled
 
 
Q