Reputation: 89
In order to scroll up and down i need to call two methods for that I have used the below method .I am using scrollview delegate method for UICollection
as it is the subview for UIScrollView
.Here is the code that I have written but the scroll is not easily moving and the result is also not accurate for some times can any one suggest.?
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView{
CGPoint mScrollPosition = [scrollView.panGestureRecognizer velocityInView:mCollectionView];
if (mScrollPosition.y > 0.0f){
NSLog(@"going down");
//Action One
mYearHeaderTitle--;
[self.mCollectionView reloadData];
}
else if (mScrollPosition.y < 0.0f){
NSLog(@"going up");
//Action two
mYearHeaderTitle++;
[self.mCollectionView reloadData];
}
}
Upvotes: 4
Views: 14877
Reputation: 119
**Use This : **
//MARK: - UIScrollview Delegate -
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
if scrollView.contentOffset.y > 0
{
if (tableView.contentSize.height - (tableView.contentOffset.y + scrollView.bounds.size.height)) == 0
{
self.count += 1
let strCount = String(self.count)
let params:[String:String] = ["search":SAFESTRING(str: self.strSearchVal!),"page":strCount,"length":"25"]
let url = API_USER.BASE_URL + API_USER.SEARCH_LISTING
self.callGetEventlist(url: url, params: params)
}
else
{
}
}
}
//MARK: - Use For Pegination -
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if (NetworkReachabilityManager()?.isReachable)! {
if (((scrollView.contentOffset.y + scrollView.frame.size.height) >= scrollView.contentSize.height ) && !isLoadingList){
self.isLoadingList = true
currentPage += 1
self.getList(page: currentPage)
}
}
}
Upvotes: 0
Reputation: 2399
In my case I had to make my view both a delegate for UITextViewDelegate and UIScrollViewDelegate. It wouldn't trigger the method until I added both. Probably because I'm in an EAGLView and not a viewcontroller.
@interface EAGLView : UIView <UITextFieldDelegate, SDWebImageManagerDelegate, UITextViewDelegate, UIScrollViewDelegate>
I also did the:
alertMessage.delegate = self;
As alertMessage is my TextView that I'm using as a Terms of Service scroller.
Upvotes: -1
Reputation: 2593
Use the following methods:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
Connect delegate to scroll view by right click on scroll view and connect to delegate method to file's owner (or)
scrollview.delegate = self;
Upvotes: 2
Reputation: 4500
Use :
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
Instead :
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
Upvotes: 2
Reputation: 1347
You can try setting self.scrollView.delegate
to the object that should act as a delegate to the scrollView.
Upvotes: 0