UIAccelerometer and UIScrollView

时光怂恿深爱的人放手 提交于 2019-12-03 20:27:55

I did this once. sv is the scroll view.

- (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;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!