In my project I need a swipe gesture action for left right movement and I need a pan gesture action for top bottom directions. When I put both gestures, only pan gesture is invoking. Does anyone have a solution for this?
UISwipeGestureRecognizer *rightSwipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:#selector(goToPreviosSong)];
rightSwipe.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:rightSwipe];
UISwipeGestureRecognizer *leftSwipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:#selector(goToNextSong)];
rightSwipe.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:leftSwipe];
for pan i'm using this code
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(panAction:)];
[self.view addGestureRecognizer:edgePanGesture];
[panGesture requireGestureRecognizerToFail:rightSwipe];
[panGesture requireGestureRecognizerToFail:leftSwipe];
Use requireGestureRecognizerToFail: to recognize the gesture if the other gesture recognizer did not executes.
[rightSwipe requireGestureRecognizerToFail: panGesture];
[leftSwipe requireGestureRecognizerToFail: panGesture];
Related
I need to implement the swipe gesture to specific limit.
I tried using the below code
UIView *viewLeftSwipe = [[UIView alloc] initWithFrame:CGRectMake(30, 200, 100, 50)];
viewLeftSwipe.backgroundColor = [UIColor whiteColor];
viewLeftSwipe.userInteractionEnabled = YES;
[self.view addSubview:viewLeftSwipe];
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipe:)];
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[viewLeftSwipe addGestureRecognizer:swipeLeft];
But it is not calling the below method
- (void)handleSwipe:(UISwipeGestureRecognizer *)swipe
{
NSLog(#"Swipe");
}
I want to hover a cell as soon as it is being pressed, but the press takes too long. I tried setting the minimum press time to .05, but it doesn't affect the recognizer.
Any suggestions:
if (cell.gestureRecognizers.count==0) {
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(userCellTapped:)];
[tap setNumberOfTapsRequired:1];
//add a long press that kills the tap if recognized
UILongPressGestureRecognizer *press = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:#selector(userCellPressed:)];
[press setMinimumPressDuration:.05];
[press setNumberOfTouchesRequired:1];
[press requireGestureRecognizerToFail:tap];
[tap requireGestureRecognizerToFail:press];
[cell addGestureRecognizer:tap];
[cell addGestureRecognizer:press];
}
My UILongPressGestureRecognizer sometimes take to fail recognizer of other gestures.
I cannot understand the exact pattern that break the recognizer of the 2 single tap gesture. I think it will happen if the user click a lot of time on my UIImageView.
I think that is related to the logic of my code... but I can't understand where is the fail.
Thanks
// adding tap gesture recognizers to the image view
UITapGestureRecognizer *singleTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleSingleTap)] autorelease];
UITapGestureRecognizer *doubleTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleDoubleTap)] autorelease];
UILongPressGestureRecognizer *longTap = [[[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(handlelongTap)] autorelease];
[singleTap setNumberOfTapsRequired:1];
[doubleTap setNumberOfTapsRequired:2];
longTap.minimumPressDuration=0.70;
longTap.numberOfTouchesRequired=1;
[singleTap requireGestureRecognizerToFail:doubleTap];
[singleTap requireGestureRecognizerToFail:longTap];
[doubleTap requireGestureRecognizerToFail:longTap];
[longTap requireGestureRecognizerToFail:singleTap];
// adding drag and drop gesture recognizers to the image view
UIGestureRecognizer *panGesture = [[[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(pan:)] autorelease];
//Adding gestures to the imageView
[imageView addGestureRecognizer:singleTap];
[imageView addGestureRecognizer:doubleTap];
[imageView addGestureRecognizer:longTap];
[imageView addGestureRecognizer:panGesture];
I have an UIWebview where i have SWIPE RIGHT and LEFT gesture to move to next pages in UIwebview. When the webview is zoomed i don't want to allow SWIPE GESTURE. I have done this in ViewdidLoad.
webView = [[UIWebView alloc]initWithFrame:self.view.bounds];
webView.frame = CGRectMake(30, 106,966,500);
webView.scrollView.bounces = NO;
webView.scrollView.delegate = self;
webView.scalesPageToFit = YES;
[self.view addSubview:webView];
I'm also adding Gesture in ViewdidLoad:
//Swipe Gesture for Webview
swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(swipeRightAction)];
swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(swipeLeftAction)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
swipeRight.delegate = self;
[webView addGestureRecognizer:swipeRight];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
swipeLeft.delegate = self;
[webView addGestureRecognizer:swipeLeft];
When zooming is done the GESTURE should not happen. How can i solve this?
I'm working on an OpenSource Magazine Engine that you can look at on GitHub:
https://github.com/interactivenyc/Defrag
I've set up a UIToolbar in a UIView I've called MenuPanel. For some reason the UIBarButtonItems in the UIToolbar aren't calling their actions properly. Here is the syntax I'm using for the buttons:
UIBarButtonItem *homeItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"home.png"] style:UIBarButtonItemStylePlain target:self action:#selector(buttonClicked:)];
What is happening is that anywhere I click on my screen, the UITapGestureRecognizer declared in my main UIViewController is being called instead. This gets setup in this block of code in my main UIViewController:
- (void)setupGestureRecognizers {
//NSLog(#"setupGestureRecognizer NEW");
UISwipeGestureRecognizer *swipeRecognizer;
swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleGesture:)];
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swipeRecognizer];
[swipeRecognizer release];
swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleGesture:)];
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeRecognizer];
[swipeRecognizer release];
swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleGesture:)];
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionUp;
[self.view addGestureRecognizer:swipeRecognizer];
[swipeRecognizer release];
swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleGesture:)];
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionDown;
[self.view addGestureRecognizer:swipeRecognizer];
[swipeRecognizer release];
UITapGestureRecognizer *tapRecognizer;
tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleTap:)];
[self.view addGestureRecognizer:tapRecognizer];
[tapRecognizer release];
}
I'm sure I have something pretty basic conceptually wrong with how I'm trying to do this. Can someone tell me how I can fix this problem?
For reference, you can see my main DefragViewController: UIViewController here:
https://gist.github.com/1431722
And my MenuPanel: UIView here:
gist.github.com/1431728
I solved my own question.
I had to tell my UIViewController to ignore touches from any UIToolbar like this:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
//ignore any touches from a UIToolbar
if ([touch.view.superview isKindOfClass:[UIToolbar class]]) {
return NO;
}
return YES;
}