Forward vertical scrolls from UIScrollView to a sibling UITableView - ios

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;
}

Related

Pass UITableView scrolling gesture to superview UITableView

I have a SuperUITableView as the main superview; inside that superview, I have another UITableView called SubUITableView.
I want to pass the scrolling gesture from the subview (SubUITableView) to the superview (SuperUITableView)
If the question is not clear, kindly ask me anything in the comments instead of downvoting.
UITableViews will confirms to scrollViewDidScroll delegate.
Inside the delegate of inner tableView, you just programmically scroll super tableView.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
UIScrollView *parentScrollView = (scrollView == self.tableView1) ? self.tableView2 : self.tableView1;
[otherScrollView setContentOffset:[scrollView contentOffset] animated:NO];
}

UIPagerView scroll problems with UIScrollView

I have an UIPagerView with its View Controllers. Each UIViewController have an horizontal UIScrollView (with 3 horizontal images, for example). See the image for reference.
When i do a horizontal swipe gesture on the scrollview, the scrollview scrolls and the pagerview doesnt. When i do a horizontal swipe gesture in any view that is not the scrollview, the pagerview scrolls its child view controllers. Everything is fine by now.
What i want to achieve is: when i scroll the scrollview to the max value (its contentSize), i want the pagerview to scroll its viewcontrollers.
Please, how can i achieve this??
To achieve what you have described, you need to set the pagerViewController as a delegate of your ScrollView.
Assuming that your ScrollView is a PageViewController, first make PagerViewController a PageViewControllerDelegate
#interface PagerViewController: UIViewController <UIPageViewControllerDelegate>
Then set the PagerViewController as the delegate of your ScrollView. Do this in viewDidLoad() method of PagerViewController
-(void) viewDidLoad
{
//some other stuff
self.scrollView.delegate = self
}
then implement didFinishAnimating delegate method in PagerViewController. It will be called whenever you scroll your scrollView controller, and you can figure out if its the last page you just scrolled by looking at the index of the latest controller. If it is, then trigger the code to scroll the PagerViewController to scroll on to the next view.

UIbutton method not getting called when added to view, scrollview & tablecell

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.

Lock handling of scroll event in UIScrollView subview (inside a UIScrollView superview)

I have a complex view hierarchy:
UIScrollView
- UITableView
- UICollectionView
The UICollectionView and UIScrollView both scroll horizontally. Now, I want to capture the swipe gesture exclusively on UICollectionView so that the superview (UIScrollView) ignores it.
User can swipe left to get to the end of UICollectionView. When at the end, the swipe gesture on UICollectionView is ignored and captured by the superview (UIScrollView) and the interface changes. How can I prevent that from happening?
Note: I'm using the default swipe functionality provided by both UIScrollView and UICollectionView i.e. I'm not adding any custom swipe gesture handling.
In your ViewController.m
-(void)viewDidLoad
{
scrollView.delegate = self;
collectionView.delegate = self;
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
if (the scrollView didn't reached the end){
then collectionView can't scroll
}else{
collectionView can scroll
}
}
You can check to see if the scrollView reached the end with the contentOffset property
Don't forget to declare that you are using the delegate of scrollView
Hope that helps

UITableView in UIView in UIScrollView. When scrolling tableview don't scroll scrollview too

I have a UITableView inside a UIView inside a UIScrollView.
Problem: when i scroll/drag the tableview, the scrollview scrolls too.
What i need is for the tableview not to pass the scroll to the scrollview. Also i need to be able to use the scrollview when i scroll it directly.
How can i do this?
Cheers
I fixed it using "hitTest" on the tableview.
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
If the event originated within the tableview, i disable the parent's scrollview scroll.
And, when the tableview's scroll has ended (scrollViewDidEndDragging) i re-enable the parent's scrollview scroll.
This seams to work fine.
Set a delegate to your tableview's scrollview (i.e your view controller)
tableView.scrollView.delegate = self;
then use those two calls
– scrollViewDidScroll:
– scrollViewDidEndDragging:willDecelerate:
to disable and re-enable your outside scrollview's scrollEnabled property

Resources