I have a custom UIView subclass that has a UITapGestureRecognizer attached to it.
I am trying to use this custom view inside of a UIView (container) inside of a UIScrollView, inside of a UITableViewCell.
So:
UITableViewCell
•UIScrollView
••UIView (container for proper contentSize on UIScrollView)
•••Bunch of UIViews with UITapGestureRecognizer (subclass)
It seems that if I don't use a 'container' view inside the UIScrollView, the taps get detected just fine. But then the contentSize is not correct and some of my custom views inside the UIScrollView are off screen and can't be accessed.
If I do use a 'container' view inside the UIScrollView, the contentSize for the scroll view is correct, but none of the custom view taps get detected.
I have tried all sorts of variations of the below with no success:
tapGesture.cancelsTouchesInView = false
scrollView.canCancelContentTouches = false
scrollView.userInteractionEnabled = true
containerView.userInteractionEnabled = true
Well I couldn't get it to work for some reason, even tried subclassing UIScrollView and the UIView for the container view.
I ended up just adding a UICollectionView to the subclassed UITableViewCell, and then setting the UITableViewController as the UICollectionViewDataSource and UICollectionViewDelegate to handle item selection.
Related
My self.view has a UIScrollView as a subview. This UIScrollView has a container UIView, which holds many UITableView's as subviews. These subviews are all configured using autolayout constraints.
So basically my scrollview is horizontally scrollable. I also have UILongPressGesture inside my UIScrollView.
My problem is didSelectItemAtIndexPath is not called while tapping over the cells inside UITableView. I have set cancelTouchesInView to NO for my UILongPressGesture but still didSelectItemAtIndexPath doesn't get called.
I don't want to add UITapGestureRecognizer to my UIScollView and manually trigger didSelectItemAtIndexPath , since I'm doing some operations in UITableView delegate methods.
How can I make my UITableView to responds to all of its delegate methods ?
I have a UITableViewController. In one of my prototype cells there is a UIScrollView with horizontal paging and a page control. I have set this up in storyboard, laying out all the elements that will display on each page of the UIScrollView, exactly how I have set a scroll view up in the past in a UIViewController. Since this UIScrollView is inside a UITableViewCell, I am confused about how to connect the page control.
1) Should the code to change the page control be in the cell class file? And if so what would that look like?
2) Also do I implement the UIScrollViewDelegate inside the UITableViewController or inside the UITableViewCell class file?
(this is in objective-c)
Having the UIPageControl code inside of the cell class seems to be the most appropriate choice. The view controller which is displaying the table/cells shouldn't be delegating this type of internal behaviour.
If you're implementing the code in the cell class then the cell class would need to conform to the UIScrollViewDelegate protocol in order to receive the scrollViewDidScroll: message. The table view controller wouldn't be involved.
This is what it the method would look like:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat pageIndex = self.scrollView.contentOffset.x / CGRectGetWidth(self.scrollView.frame);
self.pageControl.currentPage = lround(pageIndex);
}
Also make sure to set the pagingEnabled property on the scrollview to YES.
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
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).
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