So I have got this scenario:
-NavigationController
-PageViewController
-MapViewController
-UIView
-MKMapView (Full Screen)
-OtherViewController
So basically, I want it to switch pages (viewcontrollers) when catching the UIScreenEdgeGesture. But having the map in one of them, this doesn't work properly.
I have researched a lot (!) about this but still haven't found the right solution.
I believe that the correct approach here is to delegate this gesture to the nextResponder in the hierarchy.
So I have successfully captured the gesture when the user swipes on the left edge of the screen.
Right now my issue is I can't manage to pass the gesture to the UIView (MKMapView.superview).
I have two questions :
// 1. How to do it
// 2. Is this the right approach?
Let me know your thoughts on this one please!
EDIT 1:
Adding some code and Images of story board
UIScreenEdgePanGestureRecognizer *popRecognizer = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:[self.view superview] action:#selector(handlePopRecognizer:)];
popRecognizer.edges = UIRectEdgeLeft;
popRecognizer.delegate = self;
[self.mapView addGestureRecognizer:popRecognizer];
EDIT 2: I want this behaviour : Use UIScreenEdgePanGestureRecognizer without moving MKMapView
But when the gesture is recognized, I want it to switch to the page on the left (OtherViewController)
FINAL EDIT: THE workaround that I've come up with consists in putting a clear view on top of the map, leading to the desired behaviour. Not happy with the solution, but it works for now.
When you create your gesture, make the target the superview, and call the method in the superview for the action, something like:
UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:[self.view superview] action:#selector(swipeHandler:)];
Don't know if MKMapView.superview would work, that depends on if MKMapView is an instance. Hard to know what you're referring to without code.
Related
Basically I have a scrollView, on which there is another view.
On that view I also have a UITapGestureRecognizer.
I'm animating scrolling of the scrollView. However, during this scrolling animation, tap gesture recognizer doesn't actually recognize taps.
Any ideas?
Without code We can't give suggestion but try with below code might be useful for you!
tapGestureRecognizer.numberOfTapsRequired = 1
tapGestureRecognizer.isEnabled = true
tapGestureRecognizer.cancelsTouchesInView = false
For best practise, you can use button action instead of UITapGesture by adding UIButton. the reason is simple, to manage the button is far much simple then the UITapGesture but I am not saying use UIButton instead of tap gesture all the time, its all about your requirement.
For your case, add this line
view.userInteractionEnabled = false
and make sure your view is added in the UITapGestureand UITapGesture method is properly implemented in your code work.
For more basic, go with these two tutorials,
First tutorial |
Second tutorial
If you still face any problem then let me know.
We are developing an iPad application where entire UI is created using Storyboard file.
In one of the view controller scene, there is a UITableView which contains a custom cell.
When I swipe to the table cell, a delete button appears for that.
How to disable this swipe to delete functionality. We have our own Edit button on top navigation bar, which sets UITableView's editingMode. We require to disable swipe to delete funcitonality.
Here is what we have already tried:
1. Overriden swipe gesture method:
UISwipeGestureRecognizer *gestureR = [[UISwipeGestureRecognizer alloc]
initWithTarget:self action:#selector(handleSwipeFrom:)];
[gestureR setDirection:UISwipeGestureRecognizerDirectionRight];//|UISwipeGestureRecognizerDirectionRight)];
[myTableView addGestureRecognizer:gestureR];
We have tried this gesture with both, myTableView as well in CustomCell file.
2. Remove swipe gesture method:
UIGestureRecognizer* swipe = [[self.tableView gestureRecognizers] objectAtIndex:2];
[myTableView removeGestureRecognizer:swipe];
Both of those code blocks are not working for us.
This issue is there only for the iOS 7 only, as there is default swipe to delete given for UITableView.
Please suggest a solution for this.
(1.) is not really an override. It seems adding multiple recognisers could have undefined results.
(2.) looks like a private API hack, so also not advisable.
Instead, the editing behaviour of a table view is controlled by overriding these methods:
- tableView:willBeginEditingRowAtIndexPath:
– tableView:editingStyleForRowAtIndexPath:
See the documentation for details.
My table view has a text field above it. And whenever the text field is focussed, a swipe gesture is registered. When the swipe gesture is recognized, the keyboard is dismissed. The code is working for all gestures except for swipe up gesture is not working. This is my code
swipe = [[UISwipeGestureRecognizer alloc]
initWithTarget:self action:#selector(dismissKeyboard)];
[swipe setDirection:UISwipeGestureRecognizerDirectionUp];
Can someone please let me know if there is any problem?
if all the other gestures works, that means there is no logic problem.
check out spelling errors.
and reapply the swipe gesture, and check out everything (outlets etc.).
I don't know about this case, but I know that when I've had gestures on a custom container view and then added a child view with its own gestures, I've had to iterate through the child's gestures and tell them to require my gestures to fail (i.e. mine take precedence). I've done this with scroll views successfully:
for (UIGestureRecognizer *gesture in self.scrollView.gestureRecognizers)
{
[gesture requireGestureRecognizerToFail:myGesture];
}
The only times I've had problems with that are views like UITextView which remove and add gestures as you go in and out of edit mode, so that's a hassle.
Also, while I tried this with standard gestures, I've subsequently shifted to custom gestures that I've programmed to failed as quickly as possible (check the start location and fail immediately if it won't support the direction my gesture requires, rather than waiting for a bunch of touchesMoved to come to the same conclusion). If you don't want to interfere with the child view's gestures, be as aggressive as possible in letting yours fail. Maybe this isn't an issue with a swipe gesture, but it's a possible consideration if you find that your gestures end up changing the behavior of the child view noticeably.
But I suspect you'll probably just have to figure out which views have the gestures that are interfering with yours and make them require yours to fail first.
Any chance you're colliding with one of the scrollview's gestures? It doesn't seem likely if your other gestures are working, but it might be worth at least trying the gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: method in the UIGestureRecognizerDelegate protocol.
My main view controller includes a table view and also a separate view on the right that folds in when the user pans left.
I have setup a PanGestureRecogniser on this controller so that the user can use it to switch between the two views. It works fine except for one issue.
When there are only one or two cells, the user needs to pan using the empty area at the bottom not covered by cells. When there are cells that cover the entire view, or when the user pans left, the cell's swipe to delete function gets activated, since a pan gesture always fires a swipe gesture.
I want to keep the swipe-to-delete feature, but ONLY when a user swipes right on a cell.
Any left swipes/pans should always unfold the second view on the right. I'm using a custom UITableViewCell subclass. Is there any way to disable ONLY the left swipe to enter the delete mode?
This is entirely possible.
Here's the code. Add the same to your - (void) viewDidLoad method:
UISwipeGestureRecognizer * newSwipeGR = [[UISwipeGestureRecognizer alloc] initWithTarget:nil action:nil];
newSwipeGR.direction = UISwipeGestureRecognizerDirectionLeft;
newSwipeGR.numberOfTouchesRequired = 1;
[self.myTableView addGestureRecognizer:newSwipeGR];
Still enable the deletion mode as normal, but you're now find that the delete swipe only works in one direction.
I want to build an iPhone app that displays a floor plan of different regions/rooms. When a user taps on a region/room, it shows the hit-state color for a fraction of a second before sliding to a new UIView with additional text information.
Should I be setting up all the different regions via UIImages or should I draw my own floor plans programmatically? I tried drawing some rectangles programmatically, but wasn't sure if it's possible to attach tap event handlers to the graphics. Or if it's easier to maintain floor maps with unusual shapes programmatically.
My requirement was same like you. See my Question. Finally i am go ahead with UIScrollView with Zoom in out functionality. I have add multiple UIViews in Scroll and all UIViews have UILable So it will look like Room / Booth and it will look like this Question. To archive this i have face one Query and finally resolved this and implement the Floor Map Like my 1st question link.
Now to resolved your question that You have to implement UITapGestureRecognizer like below code.
UITapGestureRecognizer *fingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handlefingerTap:)];
fingerTap.delegate = self;
[fingerTap setNumberOfTapsRequired:1];
than you have to set this Gesture to your view and implement the tap method like below
[rigionView addGestureRecognizer:fingerTap];
- (void)handlefingerTap:(UIGestureRecognizer *)gestureRecognizer
{}
If you have add multiple UIViews in Scroll than implement the above code in for loop.i have done the same.
I hope it will help you..