How to pass the scroll event from scrollView to tableView - ios

I have the following view structure, the root view is UIScrollView, UIScrollView has two subViews, it is a UIView, the following is a scrollView, set contentSize scrollView for the content view size, I want to be contentOffset.y scrollView view.height when the current sliding event transfer to the following tableView to continue processing, so that tableView and scrollView continue to slide

You could catch each scroll event from your scroll view using this delegate method
- scrollViewDidScroll:
and then apply same content offset to the table view.

Related

Pause TableView scrolling

I have ViewController that have a UIView view and a TableView table inside it. View has big height so i want to hide it when user starts to scroll table - so table is now taking the whole screen.
To do that I use this method.
func scrollViewWillBeginDragging(scrollView: UIScrollView) {
//hide view or decrease it height
}
I hide view with animation - so it takes few moments to hide. The problem is - when user start to scroll table and view is begin to become smaller - some of top cells of table are already not showing because they are in top.
I want to pause scrolling - so that it can begin only after the view height is decreased. Also - I am afraid that it can be strange for users.
You need to make the height change as per user scroll to make it efficient.
override another delegate function
func scrollViewDidScroll(_ scrollView: UIScrollView) {
myView.heightConstraint = myView.originalHeight - scrollView.contentOffset.y;
}
The contentOffset property gives you the current amount of x,y scrolled in the scrollview from the origin.
What you can do is, you can give your tableView the entire screen and make another view with whatever height you want and make it as a header view of your tableView. So now the view will scroll as your tableView scrolls. Is this what you are looking for?
[tableView setHeaderView:<your-custom-header-view>];

UIScrollView and PanGestureRecognizer

I’m have a view that contains a regular UIView and a UIScrollView. The UIView sits above the UIScrollView offscreen. The UIScrollView typically occupies the entire screen. (It should be noted that I’m not using Autolayout). When the user scrolls to the top of the scrollview content I would like the UIView to start appearing on the screen. And when it reaches a certain threshold have the UIView snap into place and occupy the screen.
My initial thought was to use the UIScrollView delegate method, and adjust the superview.frame.orgin.y value when the scrollview contentOffset.y value is negative.
func scrollViewDidScroll(scrollView: UIScrollView) {
pullDownInProgress = scrollView.contentOffset.y <= 0.0
if pullDownInProgress {
self.view. = (-self.view.height / 2) - scrollView.contentOffset.y
}
}
However, this creates a stretching between the UIView and the UIScrollView due the scrollview bounce setting. If I turn off the bounce setting then the scrollview.contentOffset is never less then zero, therefore my superview frame is never adjusted.
Any suggestions on how to accomplish this?
You don't need to change the superview.frame, instead move the offscreen view down by its height so that it can appears and any bouncing effect for the scroll view might be hidden by that view.Or you can even move both the scroll view and the offscreen view with the height of the offscreen view. It really depends whether your offscreen view is transparent or not

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.

scrollview auto scroll when `pushViewController`

In a ViewController, there are three tableViews in a scrollView:
when the segment[1] tapped scrollView scroll to the second tableView, and the segment[2] tapped scrollView scroll to the third tableView
the problem is, if the second tableView is displayed now, when call [self.navigationController pushViewController:viewController animated:YES];, the scrollView auto display the first tableView,but its contentOffset is still {320,height}

Resize the subview when scrollview scroll in UIPangesture

I have Create UIScrollview Programatically.I have added 5 View and each view have Imageview with image. I am doing zoom in/zoom out image using UIPanGesture i can zoom in and zoom out image using PanGesture but when i scroll the scrollview then UIImageview not set its actual frame. i want to resize subview of scrollview when scrollview scroll.
Thanks in Advance
Set your view controller a delegate of your scrollview:
scrollview.delegate = self;
Then, implement this delegate method in your viewcontroller:
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
// resize subview of scrollview here
}
You need to set some object as the scrollview's delegate and then implement this method:
-(void)scrollViewDidScroll:(UIScrollView *)inScrollView
Then you can do whatever you would like with the subviews whenever the scrollview scrolls (this includes automated scrolling, not just when the user scrolls).

Resources