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.
Related
I have controller, call it ActionBarViewController (it inherits UIViewController). It has view, call it ActionBarView. That view has 2 subviews - contentView and actionBar. contentView frame equals to ActionBarView frame. actionBar frame is small frame at bottom part of ActionBarView frame.
I have one more controller - ListViewController (it inherits UITableViewController). I use it as childViewController with ActionBarViewController as parent. ListViewController's view (tableView) set as contentView of ActionBarView.
As result, i have UITableViewController that is childViewController. ParentViewController view has additional subview - action bar.
For correct table view scrolling i add/remove additional contentInsets of tableView on actionBar show/hide. But ListViewController add/remove contentInsets on his own when keyboard appeared/disappeared.
Finally, when keyboard shown tableView has complex bottom insets, keyboard insets and actionBar insets.
Questions:
Any body knows correct way to resolve this issue?
In which point UITableViewController change tableView insets? How to override it?
P.S.: All views and controllers creating programmatically.
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.
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 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