I've set...
self.navigationController.hidesBarsOnSwipe = YES;
I also have a UISlider in a tableHeaderView. The UISlider no longer slides when using hidesBarsOnSwipe. I assume hidesBarsOnSwipe is consuming the gesture that the slider would typically use. To get around this with traditional gesture recognizers you can use...
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
to fire more than one gesture at a time. But to get that to work you need to set the delegate, and you are not allowed to change the barHideOnSwipeGestureRecognizer delegate.
Any ideas? I'm stumped. Not sure how to get past this.
Related
I have a custom UITableViewCell with a UIButton.
UIButton blocks the swipe-to-delete gesture recognizer implemented by Apple; if the swipe starts on the button, the swipe is not recognized, otherwise the delete button appears and everything works correctly
At the moment, I have replace the UIButton by an UIImageView to get the desired behaviour.
I would like if somebody manages to make this work.
I have already tried to implement this delegate method
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
and searched the view/subviews for all its gesture recognizers and assign them the cell as delegate. I still can make it work with a UIButton.
I target ios8
Thanks
Use UILable or UIImage instead of UIButton, and set userInteractionEnabled to YES, and add a UITapGestureRecognizer gesture to it.
I've been looking for a way to intercept all touch events of an app.
I saw that I can add a gesture recognizer to the main window and get all the touches by using it's delegate method:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
NSLog(#"%#",touch);
return NO;
}
This way I don't harm all of the other touch events the app has.
The problem is that I cannot get swipe events and such this way. Moreover, I cannot override UIWindow sendEvents because my app is an outside framework.
I also do not want to add a transparent UIView on top.
Is there any other way to get swipes and other gesturs?
To intercept all touch events of an app, use a UIWindow subclass and override sendEvent:.... Every touch event passes through this bottleneck method. Be warned that you are now operating at a very low level and can easily break everything.
I managed to get this to work by using a custom gesture recognizer attached to the keyWindow and with using the method:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
Which also gives me all the touches and doesn't disturb any other recognizers.
If anyone know why I shouldn't be doing that, I'd be happy to hear about it.
I am using ECSlidingViewController for hamburger menu and I added code to my viewDidLoad method:
[self.slidingViewController.topViewController.view addGestureRecognizer:self.slidingViewController.panGesture];
Now I have pan gesture to show right menu or to hide. It's okay. But I have on view slider and it's really hard to get him working. I must tap on exact position. Is it possible to set that in exact rectangle (in view that contains slider) the slider would be answering on gesture and on other parts it would be working as now?
And one more question. When I have navigation controller with table and then I went on detail and then I show right menu it's okay but when I want to close it by pan I first go back in navigation and then close menu. Is it possible to change this order?
Have you tried setting UIGestureRecognizerDelegate and handling the both gesture recognizes in similar fashion as described in FAO?
e.g.:
#pragma mark - UIGestureRecognizerDelegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
if ([otherGestureRecognizer.view isKindOfClass:[UISlider class]]) {
return YES;
} else {
return NO;
}
}
i'm using ECSlidingViewController and i've a problem when using pan Gesture to open the sliding menu the tableview in the main view still have the scrolling gesture
i need to remove the gesture of the main view and add it back when it slide back
in the InitViewController add the following method
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
return NO;
}
if return YES it will make the undesirable behavior
What I currently have:
I have a child UIViewController inside my main UIViewController. In this child UIViewController I have an UITableView, although anything can be inside of it (UIScrollView, UIImageView, composition of different UIViews sub-classes).
On my main UIViewController I have GestureRecognizerDelegate, so I am receiving callbacks when a gesture is made, like this:
- (void)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer movedWithTouches:(NSSet*)touches andEvent:(UIEvent *)event;
- (void)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer endWithTouches:(NSSet*)touches andEvent:(UIEvent *)event;
#optional
- (void)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer beganWithTouches:(NSSet*)touches andEvent:(UIEvent *)event;
For a particular gesture done on top of the main UIViewController, I am showing a small UIView with an UIImageView. So basically when a touch is made from top to botton where the Y < 100 the UIView animates and shows the image and when I release my finger from the screen the UIView goes back to the top. It's pretty much like the notification center that Apple provides, except that I don't control the scrolling of it and it only shows for 200px from the top.
The problem:
In theory the UIView with the UIImage is the top-est UIView on my hierarchy, but when I keep moving around with my finger on it's area, I can see the UITableView underneath it, moving. For me it doesn't make sense since the UIView with the UIImageView should be capturing those gestures.
What I want:
Simply when I show the UIView with the UIImage disable all the interaction on that childViewController.
What I have tried:
Currently I have this:
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
If I put to NO, the UIView with the UIImage doesn't even show.
If I put something like myChildViewController.view.userInteractionEnabled = NO, since the gesture already started, it won't work. Of course if I use that before the gesture has started everything will work as intended. But the problem is that I won't be able to use the UITableView.
Well, in the end what's working is:
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
// Check if I am not on the Default state (UIView with the UIImageView hidden)
if(currentState != kDefaultState)
{
otherGestureRecognizer.enabled = NO;
[arrayOfDisabledGestures addObject:otherGestureRecognizer];
}
return YES;
}
When I finally close the UIView with the UIImageView I do the following:
[arrayOfDisabledGestures makeObjectsPerformSelector:#selector(setEnabled:) withObject:#YES];
To re-enabled all the gestures. I don't really like the solution, I think there should be (and I bet there are) other ways of doing this.