1

我试图从左到右自动滚动,但我还没有成功。我正在评估以下表达式以更改方向(添加或减去像素)但是当滚动到达最终它被阻止...

(xContentSize - xOffset) >= CGRectGetWidth(_scroll.bounds)

或者

(xContentSize - xOffset) > CGRectGetWidth(_scroll.bounds)

任何想法?

4

3 回答 3

5

尝试这个:

float w = scrollView.frame.size.width;
float h = scrollView.frame.size.height;
float newPosition = scrollView.contentOffset.x+w; 
CGRect toVisible = CGRectMake(newPosition, 0, w, h);

[scrollView scrollRectToVisible:toVisible animated:YES];

手动设置您想要的位置

于 2013-04-24T10:35:18.523 回答
0

最后,我得到了解决方案。

每 4.0 秒使用一个 NSTimer

[UIView animateWithDuration:3.0
                     animations:^{

                         if (_direction == 0) {
                             _scroll.contentOffset = CGPointMake((_scroll.contentSize.width - CGRectGetWidth(_scroll.frame)), 0.0);
                         }else{
                             _scroll.contentOffset = CGPointMake(0.0, 0.0);
                         }

                     } completion:^(BOOL finished) {
                         _direction = !_direction;
                     }];
于 2013-04-24T11:27:34.300 回答
0

Swift 4 - 向右滚动 70 像素,然后向左滚动(用于提示用户在UIScrollView

UIView.animate(withDuration: 0.4, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: [.curveEaseInOut, .allowUserInteraction, .autoreverse], animations: {
  self.scrollView.contentOffset.x += 70
}) { [unowned self] _ in
  self.scrollView.contentOffset.x = 0
}
于 2018-11-15T15:31:03.900 回答