【问题标题】:UIAccelerometer and UIScrollViewUIAccelerometer 和 UIScrollView
【发布时间】:2010-07-30 11:13:02
【问题描述】:

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

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

【问题讨论】:

    标签: iphone uiscrollview uiaccelerometer


    【解决方案1】:

    试试这个:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-26
      • 1970-01-01
      • 2012-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多