How to get scrollView.keyboardDismissMode delegate? - ios

I want to know when the tableView was actually dragged without adding any gesture recognizers. (I already have too many gesture recognizers)
self.tableView.keyboardDismissMode = .OnDrag

The tableview inherits from UIScrollView, so you can use the scrollview delegate UIScrollViewDelegate to see when the user starts dragging. This delegate will be set up if you have set the tableView delegate to your ViewController. The method to use is scrollViewWillBeginDragging

Related

UITableView cancels UITapGesture

uitableviewdidselect cancel outs tap gesture action
there is an UIImageView in cell.contentView and there is a tap gesture to enlarge the image the control is not going to the Tap Gesture action its passing to the tableview didselect delegate ? I am using UITableView class for my table already did userInteractionEnabled=YES & cancelsTouchesInView = NO
Make sure you set
tapGestureRecognizer.cancelsTouchesInView = NO;
It won't work because table view can't take two user interactions at a time. First it will give priority to didSelectRowAtIndexPath. You need to disable user interaction on cells. So that tap gesture will be called. Make sure that user interaction enabled for imageView.

Recognize swipe gesture in view not in subview

I have added a subview to a View Controller's view. This subview is the view of QLPreviewController.
What I am trying to achieve is to recognize swipe gestures on the subview in the parent view, i.e. the View Controller's view. In the end, I want to be able to swipe left /right on the view to load the next document for preview.
I'm aware of hit testing and understand that by just attaching a gesture recognizer to the parent view, those will not be recognized, since the subview will be the "hit-test" view.
Now what is the best (or easiest) way to recognize those gestures?
Note: I didn't manage to attach the gesture recognizers to the subview, this doesn't seem to work.
* UPDATE *
To make this more clear - this is the code from my ViewController. vContent is just a view in my ViewController, where I add the view of the QLPreviewController:
let pvVc = QLPreviewController()
pvVc.dataSource = self
vContent.addSubview(pvVc.view)
I tried adding the swipe recognizers both to the vContent and the pvVc.view. In both cases no event was fired.
let sgrLeft: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action:Selector("handleSwipe:"))
sgrLeft.direction = UISwipeGestureRecognizerDirection.Left
sgrLeft.delegate = self
On some other view the code works fine.
Any hint is appreciated!
Thx
Eau
Well, the responder chain, the unknown animal … ;-)
You can subclass the superview and override -hitTest:forEvent:.
You rarely need to call this method yourself, but you might override it to hide touch events from subviews.
Gesture Recognizers Get the First Opportunity to Recognize a Touch, so even the subview is hitTest view. the gestureRecognizer attached on superView can recognizer touch event.

Passing UIGestureRecognizer events to child TableViewCells

I currently have a setup of:
A RootVC, with a UIPanGestureRecognizer on self.view. Then the RootVC has a child UITableViewController and hence UITableViewController.view is a subview of self.view.
The cells on the UITableViewController also have gesture recognizers enabling them to be swiped sideways. This works perfectly when the UITableViewController is itself the root view controller.
My issue is that im trying to pass a specific gesture from the self.view gesture recognizer down to the table cells. I've tried delegates:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
and
-(BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer
I can correctly identify the gestures i want to be sent below and return NO in that instance but that seems to cancel the gesture instead of passing it to subviews.
I know i could just call
[self.view.subviews[0] gestureShouldBegin:gestureRecognizer];
But because its the table view cells i cannot determine which cell the gesture should be sent too.
I have been thinking something like
[[self.childViewControllers[0] cellForRowAtIndexPath:indexPath] gestureShouldBegin:gestureRecognizer];
Would work but i dont know how to determine the correct indexPath..
Any ideas?
Look at (NSIndexPath *)indexPathForRowAtPoint:(CGPoint)point
You'll need to translate the point of the gesture to the coordinates for the tableView first.

UITableView didSelectRowAtIndexPath Not Selected on UIPageViewController

I have a UIViewController that has UIPageViewController's view added to it. That UIPageViewController has a page with a subview that has a UITableView added as a subview. I am using iOS 6 and the method didSelectRowAtIndexPath is not being called when I click on the cell. There is a weird "bug" though... If I turn the page halfway and then come back to the page I was on (without completing the page turn), I'm then able to select the cell. I assume this has something to do with gesture recognizers, but I can't figure it out. I tried removing the gesture recognizers from the instantiation of the UIPageViewController, but was unable to get that to work.
I remove the tap gesture recognizers from the UIPageViewController like so, but still the buggy behavior exists...
for (UIGestureRecognizer *recognizer in pageViewController.gestureRecognizers) {
if ([recognizer isKindOfClass:[UITapGestureRecognizer class]]) {
recognizer.enabled = NO;
}
}
Any suggestions?
Subclass UIView with UITableView. let say myUIView.
Implement the UITableView delegates in myUIView.
Add myUIView as a subview of UIPageControl.
UITableView delegates in myUIView will trigger.
It turned out to be something very simple. On my UIViewController I had the autoresizingMask set to FlexibleHeight. Changing it to None for some reason fixed my problem.
// self.contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
// Changed to :
self.contentView.autoresizingMask = UIViewAutoresizingNone;
If anyone can shed some light onto the reasons why this is the case, I'd appreciate it.

touches methods not getting called on UIView placed inside a UIScrollView

I have a Custom Scroll View, subclassing UIScrollView. I have added a scroll view in my viewcontroller nib file and changed its class to CustomScrollView. Now, this custom scroll view (made from xib) is added as a subview on self.view.
In this scroll view, I have 3 text fields and 1 UIImageView(named signImageView) added from xib. On clicking UIImageView (added a TapGestureRecogniser), a UIView named signView is added on the custom scroll view. I want to allow User to sign on this view, So I have created a class Signature.m and .h, subclassing UIView and implemented the touches methods (touchesBegan, touchesMoved and touchesEnded) and initialised the signView as follows:
signView = [[Signature alloc]initWithFrame:signImageView.frame];
[customScrollView addSubview:signView];
But when I start signing on the signView, the view gets scrolled and hence the touches methods don't get called.
I have tried adding signView on self.view instead of custom scroll view, but in that case the view remains glued to a fixed position when I start scrolling. (Its frame remains fixed in this case)
Try setting canCancelContentTouches of the scrollView to NO and delaysContentTouches to YES.
EDIT:
I see that similiar question was answered here Drag & sweep with Cocoa on iPhone (the answer is exactly the same).
If the user tap-n-holds the signView (for about 0.3-0.5 seconds) then view's touchesBegan: method gets fired and all events from that moment on go to the signView until touchesEnded: is called.
If user quickly swipes trough the signView then UIScrollView takes over.
Since you already have UIView subclassed with touchesBegan: method implemented maybe you could somehow indicate to user that your app is prepared for him to sign ('green light' equivalent).
You could also use touchesEnded: to turn off this green light.
It might be better if you add signImageView as as subView of signView (instead of to customScrollView) and hide it when touchesBegan: is fired). You would add signView to customScrollview at the same place where you add signImageView in existing code instead.
With this you achieve that there is effectively only one subView on that place (for better touch-passing efficiency. And you could achieve that green light effect by un-hiding signImageView in touchesBegan:/touchesEnded:
If this app-behaviour (0.3-0.5s delay) is unacceptable then you'd also need to subclass UIScrollView. There Vignesh's method of overriding UIScrollView's touchesShouldBegin: could come to the rescue. There you could possibly detect if the touch accoured in signView and pass it to that view immediately.
When ever you add a scrollview in your view hierarchy it swallows all touches.Hence you are not getting the touches began. So to get the touches in your signon view you will have to pass the touches to signon view. This is how you do it.
We achieved this with a UIScrollView subclass that disables the pan gesture recogniser for a list of views that you provide.
class PanGestureSelectiveScrollView: UIScrollView {
var disablePanOnViews: [UIView]?
override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
guard let disablePanOnViews = disablePanOnViews else {
return super.gestureRecognizerShouldBegin(gestureRecognizer)
}
let touchPoint = gestureRecognizer.location(in: self)
let isTouchingAnyDisablingView = disablePanOnViews.first { $0.frame.contains(touchPoint) } != nil
if gestureRecognizer === panGestureRecognizer && isTouchingAnyDisablingView {
return false
}
return true
}
}

Resources