【发布时间】:2015-08-13 13:40:44
【问题描述】:
我试图在滚动视图以相同强度滚动时移动视图。
我正在尝试:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
// here I detect when user scroll
}
如何获得滚动视图正在滚动的强度?
【问题讨论】:
标签: ios iphone uiscrollview
我试图在滚动视图以相同强度滚动时移动视图。
我正在尝试:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
// here I detect when user scroll
}
如何获得滚动视图正在滚动的强度?
【问题讨论】:
标签: ios iphone uiscrollview
尝试使用这些方法:
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
//scrolling on
NSLog(@"scrollViewWillBeginDragging");
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
if(!decelerate) {
//not scrolling
}
NSLog(@"scrollViewDidEndDragging");
}
【讨论】:
您可以通过阅读scrollView 上的contentOffset 属性来做到这一点
// You can save this as a property or an iVar
CGPoint lastContentOffset;
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
lastContentOffset = scrollView.contentOffset;
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGPoint difference = CGPointSubstract(scrollView.contentOffset, lastContentOffset);
lastContentOffset = scrollView.contentOffset;
// Use difference to know by how much the scroll view scrolled
// IMPORTANT: CGPointSubstract is not a standard function, you can implement it yourself.
}
【讨论】:
我不想给你完整的代码,但我会帮助你如何实现它。
1) You need to use the time.
2) When the time difference is greater than an amount of time passed to measure (0.05s?)
3) Check what the old content offset is compared to the new one
4) The difference is your velocity
5) reset your current timer
6) set current offsets to last offset
希望这会有所帮助 本
distance calcs
CGFloat distanceY = currentOffset.y - lastOffset.y;
CGFloat distanceX = currentOffset.X - lastOffset.X;
【讨论】: