UIACCELEREMETER和UISCROLLVIEW
-
28-09-2019 - |
题
我想根据UIACCELEREMETER值滚动滚动浏览。完成此操作的最佳方法是什么?
最初,我将内容偏移设置为基于获得的加速度计值的值。然后在每个 scrollViewDidEndAnimating
, ,我再次根据加速度值设置内容偏移。我明白那个 setContentOffset
实际上,以均匀的速度滚动滚动浏览,而不会加速。但是,这种机制在滚动卷轴上似乎很生涩。
任何想法都将不胜感激。
谢谢并恭祝安康
解决方案
我做了一次。 sv
是滚动视图。
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
if (sv.tracking || sv.decelerating) return;
CGPoint pt = sv.contentOffset;
pt.x += acceleration.x * 2;
pt.y -= acceleration.y * 2;
if (pt.x < 0) pt.x = 0;
if (pt.x > sv.contentSize.width - sv.frame.size.width) pt.x = sv.contentSize.width - sv.frame.size.width;
if (pt.y < 0) pt.y = 0;
if (pt.y > sv.contentSize.height - sv.frame.size.height) pt.y = sv.contentSize.height - sv.frame.size.height;
sv.contentOffset = pt;
}
不隶属于 StackOverflow