Bug 30636 - UIPanGestureRecognizer is missing a constructor
Summary: UIPanGestureRecognizer is missing a constructor
Alias: None
Product: iOS
Classification: Xamarin
Component: General (show other bugs)
Version: XI 8.10
Hardware: PC Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2015-06-01 12:49 UTC by John Miller [MSFT]
Modified: 2015-06-11 14:09 UTC (History)
4 users (show)

See Also:
Is this bug a regression?: ---
Last known good build:


Description John Miller [MSFT] 2015-06-01 12:49:51 UTC

   UIPanGestureRecognizer is missing a constructor that accepts a selector and a token. 

**Actual Results:**

   No ctor that matches. 

**Expected Results:**

   A constructor with this signature: http://screencast.com/t/1eeeSyg27NG

**Build Date & Platform:**

   XI 8.10

**Additional Information:**

   UIGestureRecognizer does correctly have this.
Comment 1 Miguel de Icaza [MSFT] 2015-06-01 21:17:16 UTC
This method is on the base class, as it serves as infrastructure for the derived classes.

It was a mistake that we surfaced this API as public.

Why do you need it?
Comment 2 Guillaume 2015-06-03 16:57:04 UTC
** My aim
I wanted to inherit from UIPanGestureRecognizer to:
  - alter its behavior with began state as soon as user touch start and not after a min delta translation.
  - be able to reuse its velocity estimation capability without re-implementing a new system myself
  - use the proper recognizer instance type in the Action<T> used as target.

** How
I needed a ctor on my new class inheriting from UIPanGestureRecognizer like
> public MyRecognizer(Action<MyRecognizer> targetAction)
>   : base(new Selector(":target"), new MyCallbackToken(targetAction))
like so I can reuse the infrastructure already in base UIGestureRecognizer to:
  1. register an Action<T> where T is my own MyRecognizer subclass and not an Action or Action<NSObject>.
  2. support multiple targets registered on the recognizer (done by private UIGestureRecognizer.recognizers member transformed in an hashtable as soon as multiple action are registered).
  3. properly keep a reference to the targetAction delegate and prevent GC to collect it (if anonymous method) by referencing it in a MyRecognizer.MyCallbackToken instance inheriting from UIGestureRegonizer.Token base.

** My results
Inheriting UIPanGestureRecognizer already dedicated to a specific gesture and alter it appeared as a terrible mistake during testing!
I ended up using 2 different recognizers (UILongPressGestureRecognizer and UIPanGestureRecognizer) with an UIGestureRecognizerDelegate to make them run at same time.

** Conclusion
- If inheriting from UI***GestureRecognizer is really a good thing
     => all those recognizers require this ctor.
- If you are doing it wrong, just like I was
     => it is a really good thing to not have them to force you to do it the right way!

But I have not enough experience to state on that... Just hope my feedback will help you to decide :)
Comment 3 Rajneesh Kumar 2015-06-09 08:15:47 UTC
I have checked this issue and able to reproduce this. To reproduce this issue I have followed the steps and instruction provided in bug description.

Steps I followed:

1.  Create an iOS application in XS.
2. Go to FinishedLaunching method in AppDelegate.cs.
3. Create the object of "UIPanGestureRecognizer" class.
like: UIPanGestureRecognizer p=new UIPanGestureRecognizer();
4.  UIPanGestureRecognizer is missing a constructor that accepts a selector and a token.

Screencast: http://www.screencast.com/t/oPHWyFr3 

Ide Logs: https://gist.github.com/Rajneesh360Logica/7a8724540e9b2396fd1c

Environment info:

=== Xamarin Studio ===

Version 5.9.4 (build 4)
Installation UUID: 011d70a5-dede-428b-ab04-ef451c2e539d
	Mono 4.0.2 ((detached/198235d)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400020004

=== Apple Developer Tools ===

Xcode 6.2 (6776)
Build 6C131e

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: b2ebbc0
Branch: master
Build date: 2015-06-06 01:13:21-0400

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/MM/Desktop/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: (Business Edition)

=== Build Information ===

Release ID: 509040004
Git revision: 0c8e73f6b66e066a642724a8241a0998b6329180
Build date: 2015-06-08 11:30:54-04
Xamarin addins: 7e93e9c3503f28770f23ce1b7eafd829919f18e8

=== Operating System ===

Mac OS X 10.9.5
Darwin MacMini.local 13.4.0 Darwin Kernel Version 13.4.0
    Sun Aug 17 19:50:11 PDT 2014
    root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64
Comment 4 Miguel de Icaza [MSFT] 2015-06-09 09:28:47 UTC
Follow up question.

Why would you want an Action<T>?   What would be the argument of type "T" that your recognizer would receive and where would this data come from?

Could you not track all the extra recognizers in your own structure, and have a single proxy call all those?


new UIPanGestureRecognizer (x=> {
    MyFirstAction ();
    MyEcondAction ();
    foreach (var a in allMyRecognizers)
       a ();
Comment 5 Guillaume 2015-06-11 14:09:50 UTC
I can do as you said.

But as the API looked like public, I just wanted to keep the same structure as already in place to use it like

public class GestureConsumerView
    : UIView
    public GestureConsumerView()
        AddGestureRecognizer(new CustomPanGestureRecognizer(x => {
            var v = x.VelocityInView(this); //only available with UIPanGestureRecognizer, not UIGestureRecognizer
            /* my update action here using inherited methods by CustomPanGestureRecognizer */



public class CustomPanGestureRecognizer
    : UIPanGestureRecognizer
    public CustomPanGestureRecognizer(Action<CustomPanGestureRecognizer> updateAction)
        : base(Selector.GetHandle("target:"), new MyCallbackWrapper(action))

    /* Any custom recognition stuff */

    private class MyCallbackWrapper
        : UIGestureRecognizer.Token
        /* callback stuff here */

Note You need to log in before you can comment on or make changes to this bug.