how to access subview control in UITapGesture in objective- c? - ios

Hello Friends Please help me,
I have added UITapGesture on UIWindow but i can't able access parent control in screen
UIRotationGestureRecognizer *rot =[[UIRotationGestureRecognizer alloc] initWithTarget:self action:#selector(handleRotation:)];
rot.cancelsTouchesInView = NO;
rot.delegate = self;
UIPinchGestureRecognizer *pinch =[[UIPinchGestureRecognizer alloc] initWithTarget:self
action:#selector(handlePinch:)];
pinch.cancelsTouchesInView = NO;
pinch.delegate = self;
/* UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self
action:#selector(handlePan:)];
pan.cancelsTouchesInView = NO;
pan.delegate = self;*/
//circle gesture
gr = [[MDCircleGestureRecognizer alloc] init];
[gr addTarget:self action:#selector(handleGesture:)];
//[self.view addGestureRecognizer:gr];
//gr.delegate = (id<MDCircleGestureFailureDelegate>)self.view;
gr.delegate = self;
gr.cancelsTouchesInView = NO;
////Z gesture
cg = [[CharGesture alloc] initWithTarget:self action:#selector(zLetterMade:)];
cg.delegate=self;
cg.cancelsTouchesInView = NO;
//Add on window - RR
[[[UIApplication sharedApplication]delegate]window].gestureRecognizers = #[gr,cg,pinch,rot];

please confirm that you have given UIGestureRecognizerDelegate and enable interaction [[[UIApplication sharedApplication]delegate]window].userInteractionEnabled=YES;

Related

iCarousel item pinch and pan

I'm trying to implement a zoom feature for an iCarousel item view. This is my code :
NSString *pathToHDImage = [documentsFolderPath stringByAppendingPathComponent:solution.localHDURL];
if (!view) {
view = [[AsyncImageView alloc] initWithFrame:self.view.bounds];
view.contentMode = UIViewContentModeScaleAspectFit;
UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:#selector(handlePinch:)];
pinchGesture.cancelsTouchesInView = false;
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(handlePan:)];
panGesture.cancelsTouchesInView = false;
pinchGesture.delegate = panGesture.delegate = self;
[view addGestureRecognizer:pinchGesture];
[view addGestureRecognizer:panGesture];
((AsyncImageView *)view).imageURL = [NSURL fileURLWithPath:pathToHDImage];
} else
((AsyncImageView *)view).imageURL = [NSURL fileURLWithPath:pathToHDImage];
The problem is that my handlePan: and handlePinch: never get called. How can I do? The main goal is to implement zoom feature for every iCarousel item view.
Try this Code:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
I did not test but I hope it helps.
In case it does not work check out this link1 and then this link2

How can I detect longtap gesture on MapBox SDK for IOS?

How can i detect longtap gesture on MapBox SDK for IOS?
I try below code.
but mapLongTap are never called.
-(void)mapInit
{
RMMBTilesSource *offlineSource = [[RMMBTilesSource alloc] initWithTileSetResource:#"tokyo5" ofType:#"mbtiles"];
mapView = [[RMMapView alloc] initWithFrame:_mapBaseView.bounds andTilesource:offlineSource];
mapView.zoom = 0;
mapView.delegate = self;
mapView.missingTilesDepth = 5;
mapView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
mapView.adjustTilesForRetinaDisplay = YES;
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:#selector(mapLongTap:)];
[longPressGesture setMinimumPressDuration:1.0];
// [_mapBaseView addGestureRecognizer:longPressGesture];
[mapView addGestureRecognizer:longPressGesture];
[self.mapBaseView addSubview:mapView];
}
-(void)mapLongTap:(UISwipeGestureRecognizer *)gesture
{
NSLog(#"LongTap");
}
RMMapView already has a long press gesture recognizer. See -[RMMapViewDelegate longPressOnMap:at:].

Swipe left & right works all the time, but swipe up/down doesn't

I have an object based on UIView that I've set up to recognise swipe gestures. The view has another UIView based object in the middle of it.
When I swipe left or right, regardless of where I put my finger, the correct event fires.
When I swipe up or down the correct event only fires if my finger isn't starting in the subview in the middle?
Why?
Here's the init code for the object:
- (id)init
{
self = [super init];
if (self) {
[self setFrame:CGRectMake(0,
0,
[self getScreenWidth],
[self getScreenHeight])];
backView = [[UIView alloc] initWithFrame:CGRectMake(0,
0,
[self getScreenWidth],
[self getScreenHeight])];
backView.backgroundColor = [UIColor whiteColor];
[self addSubview:backView];
[self bringSubviewToFront:backView];
theCard = [[actCard alloc] init:CARD_POS_CENTER];
[backView addSubview:theCard];
[backView bringSubviewToFront:theCard];
swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self
action:#selector(showGestureForSwipeRecognizer:)];
swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self
action:#selector(showGestureForSwipeRecognizer:)];
swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self
action:#selector(showGestureForSwipeRecognizer:)];
swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self
action:#selector(showGestureForSwipeRecognizer:)];
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[self addGestureRecognizer:swipeLeft];
[swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
[self addGestureRecognizer:swipeRight];
[swipeUp setDirection:UISwipeGestureRecognizerDirectionUp];
[self addGestureRecognizer:swipeUp];
[swipeDown setDirection:UISwipeGestureRecognizerDirectionDown];
[self addGestureRecognizer:swipeDown];
NSLog(#"Enabled: %d",swipeLeft.isEnabled);
NSLog(#"Enabled: %d",swipeRight.isEnabled);
NSLog(#"Enabled: %d",swipeUp.isEnabled);
NSLog(#"Enabled: %d",swipeDown.isEnabled);
}
return self;
}
Try setting the delegate of your Upward swipe and downward swipe to be your MainViewController.Something like :
swipeDown .delegate = self;
swipeUp .delegate = self;
This should make your main view controller ( which contains the secondary UIView ) responsible for the gestures received.
Hope this helps!
Obvious! What a newb I am.
The UITextView still had scrollEnabled. That means the UITextView took the up & down swipes, they don't get passed on to the view.

iOS: The second UITapGestureRecognizer I add does not work

I have 2 UIPickerViews as InputViews for textfields. I want to detect tap events on both of them. But only the taps on the first are detected.
Here is my code in ViewDidLoad:
// for Behandler selection
_behandlerArray = [self fetchBehandler];
_behandlerPickerView = [[UIPickerView alloc] init];
_behandlerTextField.inputView = _behandlerPickerView;
_behandlerPickerView.dataSource = self;
_behandlerPickerView.delegate = self;
[_behandlerPickerView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(behandlerPickerTapped:)]];
// for Medikamente selection
_medikamenteArray = [self fetchMedikamente];
_medikamentePickerView = [[UIPickerView alloc] init];
_medikamenteTextField.inputView = _medikamentePickerView;
_medikamentePickerView.dataSource = self;
_medikamentePickerView.delegate = self;
[_medikamentePickerView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(medikamentePickerTapped:)]];
And here are the methods:
-(void)behandlerPickerTapped:(UIGestureRecognizer *)gestureRecognizer{
NSLog(#"_behandlerPickerView tapped");
}
-(void)medikamentePickerTapped:(UIGestureRecognizer *)gestureRecognizer{
NSLog(#"_medikamentePickerView tapped");
}
But only the taps on _behandlerPickerView are detected/logged.
Can I only added one UITapGestureRecognizer?
And if so, how do I know in the method, which view was tapped?

UISwipeGestureRecognizer blocked by UITapGestureRecognizer

I have a view which needs to handle pan, tap, and swipe gestures. I have pan and tap working, but when I add swipe, it doesn't work. Curiously, it seems that tap somehow blocks the swipes because if I remove the tap, then swipe works fine. Here's how I create my gesture recognizers.
- (void) initGestureHandlers
{
UISwipeGestureRecognizer *swipeLeftGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipeLeftGesture:)];
swipeLeftGesture.numberOfTouchesRequired = 1;
swipeLeftGesture.direction = UISwipeGestureRecognizerDirectionLeft;
[self addGestureRecognizer:swipeLeftGesture];
UISwipeGestureRecognizer *swipeRightGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipeRightGesture:)];
swipeRightGesture.numberOfTouchesRequired = 1;
swipeRightGesture.direction = UISwipeGestureRecognizerDirectionRight;
[self addGestureRecognizer:swipeRightGesture];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleTapGesture:)];
[tapGesture setNumberOfTapsRequired:1];
[self addGestureRecognizer:tapGesture];
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(handlePanGesture:)];
[self addGestureRecognizer:panGesture];
}
A lot of blog suggest using requireGestureRecognizerToFail to handle the case where tap fires before the double tap fires, so I tried that, but it also didn't work.
[tapGesture requireGestureRecognizerToFail:swipeLeftGesture];
[tapGesture requireGestureRecognizerToFail:swipeRightGesture];
How can I get tap and swipe in the same view?
comment or remove the lines
//[tapGesture requireGestureRecognizerToFail:swipeLeftGesture];
//[tapGesture requireGestureRecognizerToFail:swipeRightGesture];
Also set the all the guesture objects delegate to self. like this
- (void) initGestureHandlers
{
UISwipeGestureRecognizer *swipeLeftGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipeLeftGesture:)];
swipeLeftGesture.numberOfTouchesRequired = 1;
swipeLeftGesture.direction = UISwipeGestureRecognizerDirectionLeft;
swipeLeftGesture.delegate = self;
[self addGestureRecognizer:swipeLeftGesture];
UISwipeGestureRecognizer *swipeRightGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipeRightGesture:)];
swipeRightGesture.numberOfTouchesRequired = 1;
swipeRightGesture = self;
swipeRightGesture.direction = UISwipeGestureRecognizerDirectionRight;
[self addGestureRecognizer:swipeRightGesture];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleTapGesture:)];
[tapGesture setNumberOfTapsRequired:1];
[self addGestureRecognizer:tapGesture];
tapGesture.delegate = self;
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(handlePanGesture:)];
[self addGestureRecognizer:panGesture];
panGesture.delegate = self;
}
Implement the delegate method like this
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
put this one and try it,
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;
{
return YES;
}

Resources