UIAccelerometer 和 UIScrollView

发布于 2024-09-12 07:08:20 字数 126 浏览 2 评论 0原文

我想根据 UIAccelerometer 值滚动滚动视图。实现这一目标的最佳方法是什么?

我的主要问题是,使用加速度计值,我无法设置内容偏移。因为滚动视图本身使用特定的速度滚动,并且当我尝试使用加速度计值滚动时会发生抽搐。

I want to scroll a scrollview based on the UIAccelerometer values. What is the best way to accomplish this?

My main problem is that using the accelerometer values, I cannot set a content offset. Because the scrollview itself scrolls using a particular velocity and there are jerks happening when I try to scroll using accelerometer values.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小嗷兮 2024-09-19 07:08:20

试试这个:

- (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;
}

Try this:

- (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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文