1
我想滚动基于UIAccelerometer值的滚动视图。什么是完成这个最好的方法?UIAccelerometer和UIScrollView
我的主要问题是使用加速计值,我无法设置内容偏移。由于scrollview本身使用特定的速度滚动,当我尝试使用加速度计值进行滚动时,会出现混乱。
我想滚动基于UIAccelerometer值的滚动视图。什么是完成这个最好的方法?UIAccelerometer和UIScrollView
我的主要问题是使用加速计值,我无法设置内容偏移。由于scrollview本身使用特定的速度滚动,当我尝试使用加速度计值进行滚动时,会出现混乱。
试试这个:
- (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;
}