I'm guessing that it's not valid to have a . in a Selector name.

It's easier to use gesture recognizers like this:

var gesture = new UITapGestureRecognizer();
gesture.AddTarget(() => Recognized(gesture));
view.AddGetureRecognizer(gesture);

If you use AddTarget then you don't need to use a selector. It just takes 
an Action. You also don't have to set NumberOfTapsRequired if you want the 
default of 1, and you usually don't need a Delegate. The only thing your 
delegate is doing that is non-default is return true for 
ShouldRecognizeSimultaneously. You can also do this more easily:

gesture.ShouldRecognizeSimultaneously = (thisGesture, otherGesture) => 
true;

All of the delegate methods are exposed as properties on the gesture 
itself. If you assign to one of them then it creates an internal delegate 
object which just forwards to whatever you assigned to the properties. 
That means the properties for those methods are mutually exclusive with 
the delegate property: you can use one or the other but not both. I've 
found that the properties are much easier because they don't require a 
full class.

If that doesn't help then ensure that your view has UserInteractionEnabled 
set to true. I think UIImageViews might default to false.
--
Adam Kemp
[email protected]
(512) 683-6058

[email protected] wrote on 08/05/2012 09:06:44 PM:

> From: Andre Dobroskok <[email protected]>
> To: "[email protected]" <[email protected]>
> Date: 08/05/2012 09:06 PM
> Subject: [MonoTouch] UITapGestureRecognizer can't get to work
> Sent by: [email protected]
> 
> Hi All,
> 
> I am trying to implement trivial full screen image view in response 
> to user clicking a thumbnail. I have written following controller to
> show image:
> public class ImagePreviewController : UIViewController
>     {
>         private UIImage _image;
>         private UIImageView _fullScreenImageView;
> 
>         public ImagePreviewController(UIImage image)
>         {
>             _image = image;
>             _fullScreenImageView = new UIImageView(UIScreen
> .MainScreen.Bounds);
>             _fullScreenImageView.Image = image;
>             var gestureRecognizer = new UITapGestureRecognizer(this, new 

> Selector("ImagePreviewController.HandleTap"));
>             gestureRecognizer.NumberOfTapsRequired = 1;
>             gestureRecognizer.Delegate = new RecognizerDelegate();
> _fullScreenImageView.AddGestureRecognizer(gestureRecognizer);
>             this.View = _fullScreenImageView;
> 
>         }
> 
>         [Export("ImagePreviewController.HandleTap")]
>         public void Recognized(UITapGestureRecognizer recognizer)
>         {
>             _image = null;
>             this.RemoveFromParentViewController();
>         }
> 
>     }
> 
> And here is how I call it from parent controller:
>                         _fullScreenImageController = new 
> ImagePreviewController(uiImage);
>                         this.PresentViewController
> (_fullScreenImageController, true, null);

> 
> As result I get nice full size image on the screen, however tapping 
> screen has no effect and Recognized method never gets called. 
> Obviously I have done something wrong, but I can't figure out what.
> Please help.
> 
> P.S. RecognizerDelegate looks like this:
>     public class RecognizerDelegate : UIGestureRecognizerDelegate
>     {
>         public override bool ShouldReceiveTouch(UIGestureRecognizer 
> recognizer, UITouch touch)
>         {
>             return true;
>         }
> 
>         public override bool ShouldBegin(UIGestureRecognizer recognizer)
>         {
>             return true;
>         }
> 
>         public override bool 
ShouldRecognizeSimultaneously(UIGestureRecognizer
> gestureRecognizer, UIGestureRecognizer otherGestureRecognizer)
>         {
>             return true;
>         }
>     }

> 
> Cheers,
> Andre_______________________________________________
> MonoTouch mailing list
> [email protected]
> http://lists.ximian.com/mailman/listinfo/monotouch

_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to