2013-04-24 103 views
1

我試着從左向右自動滾動,但是我還沒有成功。 我評估以下expresion改變方向(增加或從其減去像素),但是當滾動到達最終它被封鎖...以編程方式從左向右滾動UIScrollView反向

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

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

任何想法?

+0

什麼ü想引用「它封殺」? – Sovannarith 2013-04-24 10:21:02

+0

sovannarith, 滾動向右移動,但是當它達到最終時,移動到左邊並無限期移動到右邊(它被阻止) – mhergon 2013-04-24 10:30:30

+0

你能告訴我你的scrollview計算嗎? – Sovannarith 2013-04-24 10:34:44

回答

4

試試這個:

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]; 

手動設置你想要的位置

+0

我需要寫這個。我的意思是在哪個滾動視圖委託方法。我在scrollviewdidscroll中寫道,但不工作 – 2014-04-21 11:33:09

0

最後,我得到了解決。

隨着每次的NSTimer4.0秒

[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; 
        }];