ios UIScrollview pass scroll event to superview - ios

I have a UIView, and the UIView can detect a pan gesture to move this UIView to left. then I add a scrollview to this UIView, and this scrollview also can move to left and right(scroll's method), in the scrollview view, I add a UITableView that can scroll up and down and The UITableCell can detect UITapGesture.
If I not use UIScrollView, when scroll the tableview to left(the tableview can not scroll to left), the UIView can detect the pan gesture and move to left, but if I use the UIScrollView, when I scroll the tableview ,the move event is detected by the UIScrollView and can not pass to it's superview ,the UIView.
How can I do to pass the move event to the UIView if the UIScrollView can not scroll because It's contentoffset.x == 0 and can not scroll to left, So my UIView can detect the pan gesture and move to left.
Thank you!

Related

Continue scrolling UITableView when superView is at the top

I have a MainViewController with a bottomSheet as a childViewController on top of it.
The bottomSheet at first is presented on 1/4 of the MainViewController, with a UIPanGestureRecognizer attached to it and a UITableView as a subView of the bottomSheet pinned to the 4 edges of the view.
I can pan the bottomSheet and move it to the top of the screen. However, when it reaches the top, I need to release my finger and pan again so the UITableView receives the touch.
I need a way so when the view is at the top of the screen, it starts scrolling the tableView.
What I have tried is UIPanGestureRecognizer's changed state and setContentOffset of the UITableView, this gave me a final result, but with some issues, as it loses the system default animations
Is there a way to continue scrolling the tableView without releasing my finger?
Give the tableView it's complete height before even panning , where tableViewHeightCon is the height constraint of the tableView dragged as IBOutlet
override func viewDidLayoutSubviews() {
self.tableViewHeightCon.constant = numberOFCells*cellHeight;
}
and when you detect the view is at most top change the top constraint of the table view like this
func scrollTableAutomatic
{
UIView.animate(withDuration: 3.0) {
self.tableViewTopCon.constant -= self.tableView.frame.size.height - self.view.frame.size.height
}
}

Why does my UITableView need to be below UIButton in the scene outliner

I have an UIView with a UIButton and a UITableView. I constrained the UIButton (left, top, right, bottom) to (0,0,0,-) with a height of 50px. Below i constrained the UITableView (left, top, right, bottom) to (0,0,0,0) so that the screen would be filled with both views as such:
In this case the UIButton is above the UITableView in the scene outliner:
However whenever I reorder the view in the UIView so that the TableView is above the UIButton in the Scene Outliner it also moves my UITableViewCells but not my UITableView:
The constraints are the same and nothing is moved except for the layering in the scene outliner. Why do my UITableViewCells move down whenever i place my UITableView above my UIButton?
Interface Builder does that when "Adjust Scroll View Insets" in view controller attributes is checked.

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

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

UICollectionView scroll if vertical, move cell if horizontal

I have a UICollectionView that scrolls vertically but only if I am not touching a cell or it's content.
UICollectionView -> UICollectionViewCell -> UIView
The UIView has a pan gesture
- (void)move:(UIPanGestureRecognizer*)recognizer{}
which I use to move the UIView around. If the UIView is in the UICollectionView it is restricted to only horizontal movement. If I move the UIView out of the bounds of the UICollectionView then it is removed from the collection.
I want the UICollectionView to scroll vertically if I am moving my finger vertically, which would have to cause the touch events on the UIView to be ignored. But if I move horizontally the touch events will not be ignored on the UIView.
I can't seem to figure out how to accomplish this. Advice would be greatly appreciated.

Resources