我想滚动一个基于UIAccelerometer值的滚动视图。实现这一目标的最佳方法是什么?
我的主要问题是使用加速度计的值,我不能设置内容偏移量。因为滚动视图本身使用特定的速度滚动,而当我尝试使用加速度计的值滚动时,会发生抖动。
发布于 2013-02-02 04:21:07
试试这个:
- (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;
}https://stackoverflow.com/questions/3370907
复制相似问题