Is this a bug or is this the expected behavior?
In terms of grabbing the p/s via VelocityInView on GestureRecognizerShouldBegin, getting 0,0 after a pan motion has started, but not stopped/reset, is expected, at least in my experience. Obj-C/Swift is going to return the same thing, do not ask me why, have to get an actual iOS dev to ask the reason on that one.
Grabbing the velocity 'anywhere' else and you should be golden, if you really need within GestureRecognizerShouldBegin
assign a private CGPoint within your UIScrollView sub-class from any other pan recognizer (I do that in the example below)...
Example output:
2015-10-26 12:07:06.676 iOSVelocity[68486:2309184] Touch-enabed Pan gesture velocity: {X=-608.4813, Y=0}
2015-10-26 12:07:06.703 iOSVelocity[68486:2309184] Touch-enabed Pan gesture velocity: {X=-1213.629, Y=0}
2015-10-26 12:07:06.726 iOSVelocity[68486:2309184] Touch-enabed Pan gesture velocity: {X=-935.5507, Y=0}
2015-10-26 12:07:06.771 iOSVelocity[68486:2309184] Touch-enabed Pan gesture velocity: {X=-1191.385, Y=-8.564461}
2015-10-26 12:07:06.772 iOSVelocity[68486:2309184] otherGestureRecognizer velocity: {X=-1191.385, Y=-8.564461}
2015-10-26 12:07:06.772 iOSVelocity[68486:2309184] otherGestureRecognizer velocity: {X=-1191.385, Y=-8.564461}
2015-10-26 12:07:08.882 iOSVelocity[68486:2309184] !!!! ShouldBegin velocity not reset !!!!
2015-10-26 12:07:08.885 iOSVelocity[68486:2309184] GestureRecognizerShouldBegin velocity: {X=-1191.385, Y=-8.564461}
2015-10-26 12:07:08.887 iOSVelocity[68486:2309184] otherGestureRecognizer velocity: {X=-1191.385, Y=-8.564461}
2015-10-26 12:07:08.889 iOSVelocity[68486:2309184] gestureRecognizer velocity: {X=0, Y=0}
2015-10-26 12:07:08.890 iOSVelocity[68486:2309184] otherGestureRecognizer velocity: {X=0, Y=0}
2015-10-26 12:07:08.891 iOSVelocity[68486:2309184] gestureRecognizer velocity: {X=0, Y=0}
2015-10-26 12:07:08.937 iOSVelocity[68486:2309184] otherGestureRecognizer velocity: {X=0, Y=0}
2015-10-26 12:07:08.938 iOSVelocity[68486:2309184] otherGestureRecognizer velocity: {X=0, Y=0}
2015-10-26 12:07:08.939 iOSVelocity[68486:2309184] gestureRecognizer velocity: {X=-336.9197, Y=0}
2015-10-26 12:07:08.940 iOSVelocity[68486:2309184] Touch-enabled Pan gesture velocity: {X=-336.9197, Y=0}
2015-10-26 12:07:08.954 iOSVelocity[68486:2309184] Touch-enabled Pan gesture velocity: {X=-650.7258, Y=0}
2015-10-26 12:07:08.961 iOSVelocity[68486:2309184] Touch-enabled Pan gesture velocity: {X=-650.7258, Y=0}
2015-10-26 12:07:08.993 iOSVelocity[68486:2309184] Touch-enabled Pan gesture velocity: {X=-914.0547, Y=0}
2015-10-26 12:07:09.027 iOSVelocity[68486:2309184] Touch-enabled Pan gesture velocity: {X=-734.1516, Y=0}
2015-10-26 12:07:09.032 iOSVelocity[68486:2309184] otherGestureRecognizer velocity: {X=-734.1516, Y=0}
2015-10-26 12:07:09.033 iOSVelocity[68486:2309184] otherGestureRecognizer velocity: {X=-734.1516, Y=0}
2015-10-26 12:07:09.060 iOSVelocity[68486:2309184] Touch-enabled Pan gesture velocity: {X=-1086.368, Y=0}
Example UIScrollView subclass:
Note: This uses shouldRecognizeSimultaneouslyWithGestureRecognizer
in order to allow auto-panning to continue after the user lifts their touch
Note2: Not sure if I captured all the gesture state permutations, so adjust as needed
using System;
using UIKit;
using CoreGraphics;
using CoreFoundation;
using CoreData;
using Foundation;
using CoreMotion;
namespace iOSVelocity
{
public class MyScroll : UIScrollView
{
UIPanGestureRecognizer panGesture;
CGPoint velocity;
public MyScroll (CGRect cGRect) : base (cGRect)
{
panGesture = new UIPanGestureRecognizer (() => {
if ((panGesture.State == UIGestureRecognizerState.Began || panGesture.State == UIGestureRecognizerState.Changed) && (panGesture.NumberOfTouches == 1)) {
velocity = panGesture.VelocityInView (this);
Console.WriteLine ("Touch-enabled Pan gesture velocity: " + velocity);
} else if (panGesture.State == UIGestureRecognizerState.Ended) {
}
});
AddGestureRecognizer (panGesture);
}
[Export ("gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:")]
public bool ShouldRecognizeSimultaneously (UIGestureRecognizer gestureRecognizer, UIGestureRecognizer otherGestureRecognizer)
{
if (gestureRecognizer is UIPanGestureRecognizer) {
var panRecognizer = (UIPanGestureRecognizer)gestureRecognizer;
velocity = panRecognizer.VelocityInView (this);
Console.WriteLine ("gestureRecognizer velocity: " + velocity);
} else if (otherGestureRecognizer is UIPanGestureRecognizer) {
var panRecognizer2 = (UIPanGestureRecognizer)otherGestureRecognizer;
CGPoint beginvelocity = panRecognizer2.VelocityInView(this);
if (beginvelocity.X != 0 && beginvelocity.Y != 0)
velocity = panRecognizer2.VelocityInView (this);
Console.WriteLine ("otherGestureRecognizer velocity: " + velocity);
} else {
}
return true;
}
public override bool GestureRecognizerShouldBegin (UIGestureRecognizer gestureRecognizer)
{
UIPanGestureRecognizer panGesture = gestureRecognizer as UIPanGestureRecognizer;
if (panGesture != null) {
CGPoint beginvelocity = panGesture.VelocityInView(this);
if (beginvelocity.X == 0 && beginvelocity.Y == 0) {
Console.WriteLine ("!!!! ShouldBegin velocity not reset !!!!");
} else {
velocity = beginvelocity;
}
Console.WriteLine ("GestureRecognizerShouldBegin velocity: " + velocity);
}
return true;
}
}
}