I want to add tap - hide table + some actions - named cancelTap
I have an UITableView and i want to add cancelTap for it, but only at empty place.
Table height is 200.
Cells fill only a half of table, and on other half (half without cells) i need to add addGestureRecognizer.
If i'm add GestureRecognizer to Table - method DidSelectCellForRowAtIndexPath does not respond.
Is it any solutions?
I just add tap to the tableView and in the delegate of the Tap set method -
(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
return _searchDisplayController.contentSize.height <= [touch locationInView:_searchDisplayController].y;
}
in this method i deside do i need to apply tap or i ned to ignore it.
Related
I have a UICollectionView and a custom UICollectionViewCell
I want to be able to catch the UICollectionView gestures as a UIGestureRecognizerDelegate, actually I want to handle some gestures collisions by using this delegate's method:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
How can I catch the UICollectionView's UIGestureRecognizerDelegate?
UICollectionView does listen for taps but not by using a UIGestureRecognizer.
But you could add your own UIGestureRecognizer for the type your interested in (like UITapGestureRecognizer for instance) to the UICollectionView, set the delegate on it and in gestureRecognizerShouldBegin: return YES or NO depending on whether you want the UICollectionView to do it's thing or not, i.e. returning NO would cancel your gesture and allow the collection view to handle the touches.
Or set delayTouchesBegan to YES if you just want your gestures to take priority over the collection view touch handling.
More info is here Collection View Programming Guide
I have created a UITableView that can perform swipe-to-delete on its table cells in normal cases, but when I put the UITableView into a UIScrollView that can be horizontally scrollable, the outer scrollview will swallow the swipe event, thus the swipe-to-delete is not workable.
I'm sorry to tell you that you have to give up one for your function since the two functions rely on the same gesture.
If you want to keep the swipe-delete, set the outer scrollview.scrollEnabled = NO. I think that would help.
If not, have a button to start the tableview edit mode. That will make you delete cell with the scrollview can be slided.
I've finally found solution!
Subclass the outer UIScrollView, and override a method
-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
#interface AllowSwipeScrollView : UIScrollView
#end
#implementation AllowSwipeScrollView
-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
BOOL inTableViewCell = .... // check the current touch is in table view cell
if (inTableViewCell) {
return NO;
}else{
return [super gestureRecognizerShouldBegin:gestureRecognizer];
}
}
#end
And make sure the UITableView instances are in AllowSwipeScrollView.
try This condition
if (ScrollView == self.tableView) return;
in scrollviewdidscroll method.
I have the UIScrollView with pagingEnabled set to YES, and programmatically scroll its content offset to a particular point where the user taps using the following code:
[self.scrollView setContentOffset: CGPointMake(x, y) animated: NO];
It scrolls successfully to this point (x,y), but now if I do a single tap ,its content scrolls up to top.
When paging is disabled , it does not scroll to top but I need paging to be enabled.
Does any one know how can it be fixed?
Try to use this function:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
check the class of the otherGestureRecognizer if it's a tap return NO, else return YES.
I have implemented a scrollview, which holds multiple copies of a custom view. The custom views contain a UIPanGestureRecoginixer that I use to swipe them to the left (to delete them). When I attempt to scroll vertically, scrolling doesn't occur if I'm touching inside of the CustomView. However if I set up the subViews and the scrollviews content size so that it scrolls horizontally this issue doesn't occur. How can I force the scrollview to scroll horizontally even if I'm touching inside of a subview?
Try to set the UIPanGestureRecoginzer's delegate and implement
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
It requires you to return a BOOL value. When you return YES, the otherGestureRecognizer will be recognized simultaneous.
I've subclassed UITableViewCell and in that class I apply a Pan gesture recogniser:
UIPanGestureRecognizer *panning = [[UIPanGestureRecognizer alloc]initWithTarget:self action:#selector(handlePanning:)];
panning.minimumNumberOfTouches = 1;
panning.maximumNumberOfTouches = 1;
[self.contentView addGestureRecognizer:panning];
[panning release];
I then implement the delegate protocol which is supposed to allow simultaneous gestures in the table's view:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
Then I place a log inside the handlePanning method just to see when it's detected:
- (void)handlePanning:(UIPanGestureRecognizer *)sender {
NSLog(#"PAN");
}
My problem is that I'm not able to vertically scroll through the list of cells in the tableview and that handlePanning is called no matter which direction I pan.
What I want is for handlePanning to only be called when there is only horizontal panning and not vertical. Would appreciate some guidance.
Have you tried setting pannings delegate property?
panning.delegate = /* class name with the delegate method in it */;
You'll also need to conform that class to UIGestureRecognizerDelegate.
Subclass the panning gesture recognizer and make it recognize only horizontal panning. There is a great WWDC 2010 video on the issue of custom gesture recognizers available. Actually there are two on that subject, check them out at https://developer.apple.com/videos/archive/:
Simplifying Touch Event Handling with Gesture Recognizers
Advanced Gesture Recognition
Add the gesture recogniser On tableview. From that, you can get the cell object. From there you can handle the cell Functionality. For each gesture, there will be a begin, changed, end state. So, store the begin position.
CGPoint beginLocation = [gesture locationInView:tblView]; // touch begin state.
CGPoint endLocation = [gesture locationInView:tblView]; // touch end state.
Using this point, you can get the IndexPath
NSIndexPath *indexPath = [tblView indexPathForRowAtPoint:beginPoint];
From this indexpath, you can access the cell.
UITableViewCell *cell = [tableview cellForRowAtIndexPath : indexPath];
Using this Cell object, you can handle it.
Have you tried setting the bounces property to NO?