我使用以下两个UIScrollView委托方法在我的UIViewController中调用另一个方法:
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
// do something
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
// do something
}
我尝试了各种不同的调用方式//做某事但最后都没有被调用,或者两个委托方法被调用,在某些情况下调用//做两次。例如:
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
if(![scrollView isDecelerating] && ![scrollView isDragging]){
//do something
}
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
if(!decelerate){
//do something
}
}
所以如上所述,如果我滚动并让它慢慢停止,它会调用scrollViewDidEndDecelerating :,但是如果我滚动并通过点击它停止它会调用scrollViewDidEndDragging:和scrollViewDidEndDecelerating:
我希望它可以调用其中一个...有什么我可以用scrollViewDidEndDecelerating做的事情:和scrollView对象来停止这个双方法调用?
答案 0 :(得分:2)
滚动视图委托完成其工作。你不能阻止它发生。但是通过简单的逻辑,您可以实现您想要做的事情。
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
dragged = YES;
// do something
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
if (!dragged) {
// do something
}
dragged = NO;
}
答案 1 :(得分:2)
//非常简单
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if(!decelerate){
// Do something
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
// Do something
}
答案 2 :(得分:0)
这似乎有效。接近EmptyStack's answer
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
if (!dragged) {
//do something
}
dragged = NO;
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
if(!decelerate){
dragged = YES;
//do something
} else {
dragged = NO;
}
}