UIImageView don't recognize gesture

AleStrAleStr ITMember

Hi

I’m developing a tool to draw freehand over a background image.
I have develop a custom control that in the iOS implementation derivers from UIView, than in his c.tor I wire up the GestureRecognizer

public class LgcDrawView_iOS : UIView {

public LgcDrawView_iOS(RectangleF frame, string imageSource) : base(frame)
{

var pinchgr = new UIPinchGestureRecognizer();
pinchgr.AddTarget ( () => { HandlePinch (pinchgr); });
(this as UIView).AddGestureRecognizer(pinchgr);

var pangr = new UIPanGestureRecognizer();
pangr.AddTarget(() => { HandlePan(pangr); });
(this as UIView).AddGestureRecognizer(pangr);
}

In that case all works as expected and when user touch the screen the right events are throw and I can manage they in HandlePan() & HandlePinch() methods implementing the draw, the pan, etc

To load the background image I had simply update my class LgcDrawView_iOS to derive from UIImageView instead of UIView as below:

public class LgcDrawView_iOS : UIImageView

The image I want appears, but the touch events aren’t throw anymore. So the draw, pan, etc don’t works.

Why that? UIImageView derives from UIView so it must works at the same way.

Thanks

Best Answers

  • adamkempadamkemp US mod
    Accepted Answer

    UIImageView by default has UserInteractionEnabled set to false, which causes it to ignore all touches. Set it to true.

Answers

  • adamkempadamkemp USInsider, Developer Group Leader mod
    Accepted Answer

    UIImageView by default has UserInteractionEnabled set to false, which causes it to ignore all touches. Set it to true.

  • AleStrAleStr ITMember

    Attached the the class code

  • AleStrAleStr ITMember

    Oh yes!!!
    Thanks @adamkemp !!!!!

  • AleStrAleStr ITMember

    I see now also the Draw(CGRect rect) method I had override is not called if I derive from UIImageView, than the pan works, but anything is drawn over the image.
    May be do you know why that also?

Sign In or Register to comment.