I am creating a storyboard app where the view is changed when the user performs swipe gestures. The issue I am having is that when you drag and drop a gesture recognizer onto the view from themain.storyboard file, the gesture is recognized from anywhere inside the UIView. Basically, I need to recognize a gesture that is performed in a specific area on the screen, similar to how you drag down the notification center in IOS 6. If this is unclear or you need more details, feel free to ask.
Thanks in advance for any help!
I am not sure if this will help you or you tried something like this, but i want to share my idea.
You can try UISwipeGestureRecognizer in your ViewControl.m like below:
UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(swipeToDoMethod)];
[swipeGesture setDirection:UISwipeGestureRecognizerDirectionRight];
[[self innerView] addGestureRecognizer: swipeGesture];
You can add an inner view into your main view and add this gesture to that view.
Hope this helps you, good luck! :)
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(SwipeView)];
[swipe setDirection:UISwipeGestureRecognizerDirectionLeft];
[[self innerView] addGestureRecognizer: swipe];
//UISwipeGestureRecognizerDirectionRight (or) up (or) down
Use another UIView with 0 visibility, put it on area where you want recognize a gesture and then add gesture to this UIView.
This is just an idea.
Hope this will help you.
You can add a subview into your view, set the subview's frame to the area where you want to catch the swipe gesture, add recognizer to it, and set its background color to clear color. Hope it help.
Adding Swift version:
//Add gesture recognizer
let swipeGesture = UISwipeGestureRecognizer(target: self, action: #selector(dismissShowMessageAndButtonDueToSwipeUp))
swipeGesture.direction = .up
backgroundView.addGestureRecognizer(swipeGesture)
Related
I am using iCarousel to display an array of images and I want to disable the swipe gesture. I did not find that in the documentation. not sure if this is doable or not
If you want to disable the swipe gesture then I think are you want to do something like programatically change the image.
For very simply disable the user interaction of carousel.
If you using storyboard then simple remove checkmark of User Inreaction Enabled
If you use by code then following code to disable the User Inreaction Enabled
yourcarousel.userInteractionEnabled = FALSE;
May this help lot to solve your problem.
#Junchao GU If you are Using
https://github.com/nicklockwood/iCarousel
They are using Tap gesture and pan gesture
You have to Comment
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(didPan:)];
panGesture.delegate = (id <UIGestureRecognizerDelegate>)self;
[_contentView addGestureRecognizer:panGesture];
//add tap gesture recogniser
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(didTap:)];
tapGesture.delegate = (id <UIGestureRecognizerDelegate>)self;
[_contentView addGestureRecognizer:tapGesture];
in iCarousel.m File
I hope this will help you
It's bad idea to change source code of iCarousel. I think it's better to do next:
carouselView.contentView.gestureRecognizers?.removeAll()
Hope it helps to someone
I'm trying to add a very simple swipe up gesture to one of my views. The gesture does not work at all unless I apply an outward/opposite pinch gesture with two of my fingers. I am creating the gesture connections via IB. I have set up the gesture properties to Swipe: Down and Touches: 1. However it will only work with a 2 finger outward pinching motion? What is going on? Thanks.
Edit:
Ok, I've tried coding it out rather than using interface builder and I'm getting the same results. Here is the code I'm using
UISwipeGestureRecognizer *swipeUpOnVideoView = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:#selector(SwipeUp:)];
swipeUpOnVideoView.direction = UISwipeGestureRecognizerDirectionUp;
swipeUpOnVideoView.numberOfTouchesRequired = 1;
[self.playerView addGestureRecognizer:swipeUpOnVideoView];
As you can see I am specifically designating only 1 touch, however my SwipeUp: method will only execute if I use an outward pinching motion with two fingers???
check this it working proper in my application:
UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(swipeUp:)];
[swipeUp setDirection:UISwipeGestureRecognizerDirectionUp ];
[self.view addGestureRecognizer:swipeUp];
- (IBAction)swipeUp:(UISwipeGestureRecognizer *)recognizer
{
// do you stuff here
}
May be it will help you.
Happy coding...:)
It turned out I had a number of other UITapGestureRecognizers that were on my Xib file. Even though I wasn't calling them in the code anywhere they were associated with views on my page via the connections inspector. For some reason this interference made it so that my single finger swipeGesture would only register if I used a two finger pinching motion.
Deleting multiple UITapGestureRecognizers from my xib and then writing the code for the UISwipeGestureRecognizer programmatically fixed the problem for me.
I want to create custom Gesture Recognizer.
For Example:
if user pan the screen from top to bottom some distance from there if the finger move left direction some distance, i need to invoke some method from view. same if the finger move right direction means some other function should get invoke.
For this functionality
1. can i use UIPanGestureRecognizer and detect the user interaction throw the translation position,
2.There is any way to implement my own custom GestureRecognizer
(like: UIPanLeftLGestureRecognizer for user drag the finger from top to bottom some distance and moved left from there, UIPanRightLGestureRecognizer for user drag the finger from top to bottom some distance and moved right from there.)
Which is the best way to achieve the solution for this problem. kindly guide me.
Thanks in advance.
I would use two UISwipeGestureRecognizers with different directions like this:
UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(swipedDown:)];
swipeDown.direction = UISwipeGestureRecognizerDirectionDown;
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(swipedRight:)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
And don't forget to add these gesture recognizers to appropriate view
I am developing an app and I want to scroll through different UIViewControllers with a UISwipeGestureRecognizer.
Everything works, but there is one thing where I couldn't find a solution for.
I add the UIGestureRecognizers like this
- (void)viewDidLoad {
[super viewDidLoad];
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(swipeLeft)];
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[self.view addGestureRecognizer:swipeLeft];
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(swipeRight)];
[swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
[self.view addGestureRecognizer:swipeRight];
}
Now I want to know if it is possible to except a part of the self.view where it is possible to swipe to a different view.
I want to do this around a UISwitch.
Can someone please help me?
Best regards,
Lukas Goes
You can use another UIView and add it to self.view. Those UISwipeGestureRecognizer won't work inside that UIView.
Add another UISwipeGestureRecognizer to the switch, and, on your original swipe gesture recognisers, call requireGestureRecognizerToFail: on the switch's new recognizer.
Hope that makes sense, it's such a verbose class... :\
I suggest you to use the delegate method of a gesture recognizer : gestureRecognizer:shouldReceiveTouch:.
In the touch parameter, you have many information, like the position in the screen. You can use this position and test if it is above the switch frame. Return yes or no depending of if you want to trigger the selector associated to the gesture recognizer or not.
I want the user to be able to swipe left, right, upward and downward on a UIWebview, but I don't want the HTML/Javascript to process those swipes-- I want to do that myself.
Is that possible: To intercept just the swipes? I want the taps still to go through to the UIWebview.
Thanks.
Sure thing.Just attach UIGestureRecognizer subclass to that view and hold on for calls...
UISwipeGestureRecognizer* leftSwipeRecognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:#selector(someAction)];
leftSwipeRecognizer.numberOfTouchesRequired = 1;
leftSwipeRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
leftSwipeRecognizer.cancelsTouchesInView = YES;
[self.webView addGestureRecognizer:leftSwipeRecognizer];
there is some sample for left swipe gesture. You can set more with very similar approach...Hope that helps.
If you add a UISwipeGestureRecognizer onto the UIWebview with
addGestureRecognizer:
it will allow you to get those events. I believe the default is to only allow one recognizer at a time, but I'm not sure if that applies to individual gesture types or across all gesture types, so this may only be the first step in solving your problem.