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.
Related
I have a view controller with this hierarchy:
View Controller:
UIScrollView (scrollable horizontally)
UITableView (scrollable vertically)
I want to forward the vertical scrolls from my UIScrollView to the sibling UITableView, so that when the user scrolls up on the UIScrollView, the UITableView will scroll up instead. What would be the best way to do it?
I have tried these:
Detecting the vertical scroll in scrollViewDidScroll, it doesn't get called because the contentOffset of the scroll view does not change.
Subclassing the UIScrollView and overriding touchesMoved, I can't forward the touches to the table view because I don't have a reference to it in this class.
If the tableview is contained within the scroll view I believe you can set up the scroll view's gesture recognizers to respond only if the table view's gesture recognizers fail. I haven't had a chance to try this, but you should be able to set up a dependency between the gestures for each of the views.
UITableView* tableView = ...;
UIScrollView* scrollView = ...;
for (UIGestureRecognizer* r in scrollView.gestureRecognizers)
{
for (UIGestureRecognizer* tableRecognizer in tableView.gestureRecognizers)
{
[r requireGestureRecognizerToFail:tableRecognizer];
}
}
This will make your scroll simultaneously with UITableView and UIScrollView and apply #Stephen Johnson's block
- (BOOL)gestureRecognizer:(UIPanGestureRecognizer *)gestureRecognizer
shouldRecognizeSimultaneouslyWithGestureRecognizer:(UISwipeGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
I am doing following steps and having problem with UIButton not getting called.
1) I create UIbutton objects array using for loop. called addTarget for all buttons and set tags also.
2) Used above array, placed all buttons to look like table columns in a view.
3) Add the above view in scroll view.
set scrollview content size = view size
4) Now add above scrollview to cell.contentView as subview.
The issues I'm facing are :-
1) The scroll view not getting scrolled horizontally.
2) The button is not calling its methods
Your Using Tableview and Scrolle view , Both are no need , If using Tableview why scroll view
If your using only scroll view follow below url
Horizontal scroll with buttons in ios?
If you want scroll view to scroll in table view cell you have to provide delegates to both table view and scroll view and make them implement:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES; }
Do not forget that content size of the scroll view must be bigger than it's frame size in order to scroll. Also, try setting contentView.userInteractionEnabled = NO; for button to become click-able.
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 have a screen which has two UIScrollViews. Inside the scrollview is a zoomable UIImageView.
I'd like to achieve the same scrolling and zooming inside one scrollView to be applied to the other one. i.e. if the user pans across the image, both scrollviews pan their images at the exact same rate. If the user pinch zooms the image in one, the other zooms exactly the same amount.
I've read on here about using the zoomToRect:animated: call. I'm not sure exactly how to implement that, so I've tried the following - but it doesn't seem to yield the right results. NB. the scrollView contain self.imageViewLeft. self.scrollViewRight is the scrollView not being touched.
- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
CGRect visibleRect = [scrollView convertRect:scrollView.bounds toView:self.imageViewLeft];
[self.scrollViewRight zoomToRect:visibleRect animated:false];
}
I solved it guys! Props to me.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView == self.scrollViewLeft) {
[self.scrollViewRight setZoomScale:[scrollView zoomScale]];
[self.scrollViewRight setContentOffset:[scrollView contentOffset]];
} else {
[self.scrollViewLeft setZoomScale:[scrollView zoomScale]];
[self.scrollViewLeft setContentOffset:[scrollView contentOffset]];
}
}
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.