UIGesture Recognizer for Scrolling? - swift

I was wondering if there is a UIGesture Recognizer for scrolling, like on a tableView?
So, like the second a user starts scrolling on the tableView, the UIGesture Recognizer is triggered? I tried UISwipeGestureRecognizer but that did not do that trick.
I essentially just want to detect when a user starts scrolling on a tableView, and then update a value based on this. Is there anything designed for this purpose in xCode?
plz help I have spent 3 days on this one thing :)
thank you so much

you can use scrollview delegate method for that purpose
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
if scrollView == tblview{
//Do your code here
}
}

Related

Swift Scroll down should make Bar Item disappear

I want that the Bar Button Item diappear when I scroll down. My problem is that I don't know how to detect the scroll? I have tried some code but nothing worked. For example:
func scrollViewDidScroll(_ scrollView: UIScrollView) {
print("123")
}
(Don't work, I call the method in viewDidLoad())
Also I don't know where I have to call the method. In viewDidLoad(), viewDidAppear() or somewhere else? I am new in Swift, sorry.
Does anyone know the answer?
The thing is you are calling it from viewDidLoad, that gets called only once when the view is loaded. You need to place this scrollViewDidScroll
function separately, after viewDidLoad for example, but not inside of it.
Also make sure you implemented UIScrollViewDelegate in your file. Then you can add scrollViewDidScroll method to detect when is the view scrolled and print('123') inside of it.
Also make sure to set your scrollView.delegate = self in your viewDidLoad.

TVOS - UICollectionView inside scrollview - scrollview doesn't scroll

I have a CollectionView that is inside a contentView within a scrollview.
If I reach the second row of the collectionview that is hidden, the scrollview won't seem to scroll up to show the second row. It could be the focus that's doing this, just not sure how I can handle this.
Thanks!
I fixed the same issue disabling Scrolling Enabled option on particular UICollectionView.
Now when UICollectionViewCell is focused it is scrolling properly.
I Know this is not ideal solution but it seams to me that it's kind of bug.
Scrolling Disabled
Hope this helps. I'm still looking for solution without limitations.
As an improvement to the previous answer by tomaspavlic, if you have a UICollectionView that scrolls horizontally inside of an existing UICollectionViewCell (of a UICollectionView that scrolls vertically), you can implement the following as a part of the parent cell:
- (void)didUpdateFocusInContext:(UIFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator
{
self.collectionView.scrollEnabled = [context.nextFocusedView isDescendantOfView:self];
}

iOS UIScrollView cancel UIButton touch on scroll

I have some UIButtons within a UIScrollView, but I do not want to delay the button touches. However, as soon as the scroll view detects a drag/scroll, I want to cancel the UIButton touch and proceed with the scrolling of the UIScrollView.
I have included the following...
_scrollView.delaysContentTouches = NO;
...but (obviously) the button touch does not cancel when dragged. Does anyone have any suggestions as to how I can implement this functionality?
You can override this method of UIScrollView.
-(BOOL)touchesShouldCancelInContentView:(UIView *)view
{
return YES;
}
And in your UIButton, you should add different method for different control events.
show highlight effect for UIControlEventTouchDown.
trigger button for UIControlEventTouchUpInside | UIControlEventTouchUpOutside;
clear highlight effect for UIControlEventTouchCancel.
You could use scrollViewWillBeginDragging to fire off a notification and handle the button canceling by listening for it in your buttons' code. I think this is what you are trying to do, but I'm not sure if I have understood your question correctly.

tableheaderview scroll event

I use UITableViewController, and I implement
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
//my code
}
inside "//my code", how can I know that the scroll event was fired from tableheaderview area, not anywhere else in my table, in other words, how to know that the start of scrolling event was in table header view or not.
Thanks in advance.
NSLog(#"scrollView.contentOffset.y= %f",scrollView.contentOffset.y); and
NSLog(#"scrollView.contentOffset.x= %f",scrollView.contentOffset.x);
using these you can get the position of the scrolling tableview.may be it will help you.

Touch on UIButton in a UITableViewCell cannot scroll the table

I need to have a UIButton inside a UITableViewCell, everything works fine except when I touch inside the button and move my finger, the table does not scroll.
I tried to subclass UIButton and in touchesMoved: method send the same message to self.nextResponder, or call touchesCancelled and hope it will pass the touch event to next responder, they both do not work.
Is there any good way to solve this problem? Currently I am adding a UIView on top of the UITableViewCell, and detecting touch events manually, passing result to the button or the rest of the cell respectively, but this is a little bit dirty.
What you can try is setting the delaysContentTouches property of the UITableView to YES.
Additionally you can set the canCancelContentTouches to YES.
If the value of this property is NO, the scroll view does not scroll
regardless of finger movement once the content view starts tracking.
Source: UIScrollView Class Reference
Try:
_yourTableView.delaysContentTouches = YES;
_yourTableView.canCancelContentTouches = YES;
The best way is to make a custom cell and do your work neatly.
Check the Apple docs