iOS 13 UIPanGestureRecognizer behave differently from iOS 12 - ios

I have a custom scroll view that works well before iOS 13 that uses UIPanGestureRecognizer:
_panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(handlePan:)];
_panRecognizer.delegate = self;
- (void)handlePan:(UIGestureRecognizer *)gestureRecognizer
{
UIPanGestureRecognizer* pgr = (UIPanGestureRecognizer*)gestureRecognizer;
if (pgr.state == UIGestureRecognizerStateChanged) {
// do something
}
}
Now it didn't work well with iOS 13. The handlePan function does not get called anymore until 3 fingers are panning together. In iOS 12, this function will be called when just 1 finger is moved.
I have tried setting the min/maximumNumberOfTouches but not working. Is there anything changed?

It sounds like your gesture is now competing with a system gesture. Did you check the .gestureRecognizers property of the view to see if something changed?
You might have to implement gestureRecognizer(_:shouldRecognizeSimultaneouslyWith:) delegate method, by default it returns false.

Related

numberOfTouchesRequired only working for :1 / only working on iPad

I set my GestureRecognizer like this
UITapGestureRecognizer *singleFingerTap =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:#selector(handleSingleTap:)];
[self addGestureRecognizer:singleFingerTap];
singleFingerTap.numberOfTapsRequired = 3;
and the selector:
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer {
NSLog(#"yyeyyyyeyyyyyeyyyyye");
}
The class is a subclass of UIView and I want the selector to be fired on the third time - but it only works when setting numberOfTapsRequired to 1.
I wondered why the gestureRecognizer never recognized anything so I changed and swapped so many things until I realized it's working perfectly fine except that it won't do anything when the numberOfTapsRequired is anything but 1.
Any ideas about this?
EDIT: It somehow does work on iPads with iOS 7 and iOS 8. I would have guessed there is something with the constraints limiting the touch area but the 1 click does work on all devices so what else can be the difference here?

how do you make flappy bird flap?

So I was just trying to make a replica of flappy bird. But, I was wondering how to achieve a bird flap? I thought of using the method
- (void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event
but I noticed that if you use this method and press down on the screen, the bird will flap continuously. I just want the bird to flap when I tap the screen, and if I press down on the screen it will behave the same way as tapping once.
Is there a class reference that utilizes these sort of action?
For getting the tap event, you can use the UITapGestureRecognizer provided by Apple.
Simply initiate it, set the parameters according to your requirements and add it to the view you want to record the tap.
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleTap:)];
tap.numberOfTapsRequired = 1;
tap.numberOfTouchesRequired = 1;
[demoView addGestureRecognizer:tap]; // The gesture recognizer is being added to demoView
[tap release]; // In case of not using ARC
And the define the selector which you mentioned in the initialization.
- (void)handleTap:(UITapGestureRecognizer *)recognizer{
// Handle the tapping here
}
I´m very frustrated because I can´t draw the Ground like in Flappy Bird... I try to use this method:
private void drawGround(){
for(Rectangle mRectangleGroundHelper : mArrayGround){
if(spawnGround & mRectangleGroundHelper.x<0){ // spawn Ground if the actual ground.x + ground.width() is smaller then the display width.
mArrayGround.add(mRectangleGroundHelper);
spawnGround = false;
}
}
for(Rectangle mRectangleGroundHelper : mArrayGround){
if(mRectangleGroundHelper.x < -mTextureGround.getWidth()){ // set boolean to true, if the actual ground.x completely hide from display, so a new ground can be spawn
spawnGround = true;
}
}
for(Rectangle mRectangleGroundHelper : mArrayGround){ // move the ground in negative x position and draw him...
mRectangleGroundHelper.x-=2;
mStage.getSpriteBatch().draw(mTextureGround, mRectangleGroundHelper.x, mRectangleGroundHelper.y);
}
}
You can download app at here

UIPanGestureRecognizer not working when slide in from top

i have a problem with the UIPanGestureRecognizer behavior.
All works great unless I slide in from the top of my iPad. Top means here the side where the camera is located, no matter how the current device orientation is.
With the following code i debug the UIPanGestureRecognizer behavior:
- (void)viewDidLoad
{
[super viewDidLoad];
_pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(panGesture:)];
[self.view addGestureRecognizer:_pan];
}
- (void)panGesture:(UIPanGestureRecognizer*)gesture
{
if (gesture.state == UIGestureRecognizerStateBegan) {
NSLog(#"BEGIN");
} else {
NSLog(#"GO");
}
}
So when i slide in from the top nothing happens.
It seems that iOS would catch that gesture, perhaps it is related to the notification center?
In principle it seems possible to get that gesture because i saw this on other apps.
What am I missing here?
Apple says in their transition guide that the existence of the notification center means that your touches at the very bottom and very top of the screen may be canceled. I think this is likely an example of that.

swipe and pan gesture overlap

is it possible to let a specific gesture fail so the next possible gesture is recognized?
to be more specific, look at the sample snippet:
UISwipeGestureRecognizer *swipeLeft = [initialize UISwipeGestureRecognizer... #selector(handleSwipe:)]
swipeLeft = UISwipeGestureRecognizerDirectionLeft;
swipeLeft.delegate = self;
UIPanGestureRecognizer *pan = [initialize UIPanGestureRecognizer... #selector(handlePan:)]
pan.delegate = self;
[pan requireGestureRecognizerToFail:swipeLeft];
the above code states that if swipe left is not recognized by the device, pan gesture handler will be used.
so my question: is it possible to let swipeLeft intentionally fail (after being recognized as swipe left touch by the device) based on some criteria that is checked on handleSwipe, and let the pan gesture handle the touch input instead?
thanks.
Check out the UIGestureRecognizerDelegate protocol here:
https://developer.apple.com/library/ios/documentation/uikit/reference/UIGestureRecognizerDelegate_Protocol/Reference/Reference.html
Specifically, the
gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
method might be useful. If you simply return YES from this method, both gestures can be recognized at the same time, so you can respond properly to both.
Assuming you have some other handler implemented for the pan gesture, can't you just do:
-(void)handleSwipe:(id)sender {
if //criteria is met to ignore left swipe
{
[self handlePan:self];
}
}
-(void)handlePan:(id)sender {
// handle pan gesture here
}

Rotating MapView in iOS6 on User Gesture

It seems you cannot rotate the map view using user's two finger gesture anymore. It has been a while since I did any iOS development but pre-ios6 it was automatically enabled.
Is this the case or is it me being ridiculous? It seems to me that its a very basic requirement for developers to be able to allow their users to rotate the map.
Any links to documentation that specifically says we can't rotate or some clarification would be much appreciated.
Try UIRotationGestureRecognizer to rotate map.Following code will help you.
UIRotationGestureRecognizer *rgrr = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:#selector(rotateMap:)];
[mapView addGestureRecognizer:rgrr];//mapView -->your mapview
rgrr.delegate = self;
////////
- (void) rotateMap:(UIRotationGestureRecognizer *)gestureRecognizer{
gestureRecognizer.view.transform = CGAffineTransformRotate(gestureRecognizer.view.transform, gestureRecognizer.rotation);
gestureRecognizer.rotation = 0; }

Resources