2011-01-03 21 views
1

私はスクロールビューを持つiPhoneアプリケーションを作っています。iPhone SDKのボタンをクリックしてScrollViewを水平方向にスクロールする方法

私はスクロールビューの左右にボタンを持っています。

これらの2つのボタンをクリックすると、スクロールビューが水平方向にスクロールします。

これらのボタンをクリックしてスクロール表示をスクロールするにはどうすればよいですか?

助けてください。

ありがとうございました。 scrollview与え

答えて

4
- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated 
3

は、あなたが新しいオフセットを設定する前に、ページpage++;その後

NSInteger page = scrollView.contentOffset.x/scrollView.frame.size.width; 

を計算することで、現在のページを決定することができる

NSInteger page = ..// determine page 
CGPoint off = CGPointMake(page*scrollView.frame.size.width,0); 
[scrollView setContentOffset:off animated:YES]; 

を呼び出し、scrollViewと呼ばれます。

1

サンプルコード:

float width = scrollView.frame.size.width; 
float height = scrollView.frame.size.height; 
float newPosition = scrollView.contentOffset.x+width; // or - 
// probably check if position is negative 
CGRect toVisible = CGRectMake(newPosition, 0, width, height); 
[scrollView scrollRectToVisible:toVisible animated:YES]; 
関連する問題