Tom Greco Tom Greco - 4 months ago 14
Swift Question

Swift UIView blocking user interaction of image view

I've got a UIImageView which when a user presses on it and holds on it the image changes to another image and when released will return to the original image.

Now where the problem comes in is there is a UIView that sits directly on top of the UIImageView and is the exact same size of it. (I use it to hold a crop able image later in my project).

When the UIView is there I can't seem to get the long press on the UIImageView to work anymore.

I can't place the UIView below the UIImageView because there is a user interaction for the UIView at a later point.

I've tried

@IBOutlet weak var crop_view: CroppableUIView!
crop_view.userInteractionEnabled = false
crop_view.alpha = 0.0


I've got user interaction enabled for my image view and it's alpha is 1.0.

I can't seem to get this working.

Any suggestions on how to enable my image_view to pickup the user interaction and not the UIView but still be able to change those settings at a later point for example if a button is clicked set the user interaction to work on the UIView and not the image view ?

Answer

I can't place the UIView below the UIImageView because there is a user interaction for the UIView at a later point.

Actually you can. Place the crop_view below the image view until you need it, then call:

view.insertSubview(crop_view, aboveSubview: imageView)

That will move the crop_view above the image view.