UIScrollView
ページング付きの水平があります。2 つのボタンがあります。scrollView
1 つは左にスクロールし、もう 1 つは右にスクロールします。
左のコード:
- (IBAction)goLeftAction:(id)sender
{
CGFloat pageWidth = _theScrollView.frame.size.width;
int page = floor((_theScrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
if(page>0){
page -=1;
[_theScrollView scrollRectToVisible:CGRectMake(_theScrollView.frame.size.width*page, 0, self.view.frame.size.width, self.view.frame.size.height) animated:YES];
}
}
最初のページ (page=0) で左を押すと、ボタンがscrollView
バウンス効果を表示するようにします。
これを達成する方法を見つけるのを手伝ってください。
編集:
誰かがそれを必要とする場合のコードは次のとおりです。
最初に追加したのはgoLeftAction:
[_theScrollView setPagingEnabled:NO];
[_theScrollView setScrollEnabled:NO];
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(bounceScrollView) userInfo:nil repeats:NO];
そして、この次:
- (void)bounceScrollView
{
[self.theScrollView scrollRectToVisible:CGRectMake(100, 0, self.view.frame.size.width, self.view.frame.size.height) animated:YES];
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(unbounceScrollView) userInfo:nil repeats:NO];
}
- (void)unbounceScrollView
{
[self.theScrollView scrollRectToVisible:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) animated:YES];
[_theScrollView setPagingEnabled:YES];
[_theScrollView setScrollEnabled:YES];
}