问题
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];
}
}
回答1:
Use :
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
Instead :
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
回答2:
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;
回答3:
You can try setting self.scrollView.delegate
to the object that should act as a delegate to the scrollView.
回答4:
Set your view controller up as a <UIScrollViewDelegate>
回答5:
**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
{
}
}
}
回答6:
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.
来源:https://stackoverflow.com/questions/18058851/uiscrollview-delegate-methods-not-calling-properly