今回は指ではなくボタンで画像をめくれるようにする。
サンプル実行
ツールバーに移動用のボタンを付けてそれで移動する。
実装
移動用の公開メソッドを用意した。
- (void)movePreviousPage; - (void)moveNextPage; - (void)movePreviousPageAnimated:(BOOL)animated; - (void)moveNextPageAnimated:(BOOL)animated;
実装は既にあるメソッドの組み合わせで簡単にできた。
- (void)movePage_:(BOOL)animated
{
 CGSize size;
 if (self.showcaseModeEnabled) {
  size = self.scrollView.bounds.size;
  size.width -= spacing_.width;
 } else {
  size = self.bounds.size;
 }
 size.width += spacing_.width;
 
 passDidScroll_ = YES;
 [self.scrollView setContentOffset:CGPointMake(
  self.contentOffsetIndex*size.width, 0)
        animated:animated];
}
- (void)movePreviousPageAnimated:(BOOL)animated
{
 if (self.currentPage<= 0) {
  // do nothing
  return;
 }
 
 self.currentImageIndex--;
 self.contentOffsetIndex--;
 self.pageControl.currentPage--;
 [self setupPreviousImage];
 [self movePage_:animated];
}
- (void)movePreviousPage
{
 [self movePreviousPageAnimated:YES];
}
- (void)moveNextPageAnimated:(BOOL)animated
{
 if (self.currentPage >= [self numberOfImages]-1) {
  // do nothing
  return;
 }
 self.currentImageIndex++;
 self.contentOffsetIndex++;
 self.pageControl.currentPage++;
 [self setupNextImage];
 [self movePage_:animated];
}
- (void)moveNextPage
{
 [self moveNextPageAnimated:YES];
}ソースコード
GitHubからどうぞ
xcatsan's iOS-Sample-Code at 2010-10-23 - GitHub




Responses
Leave a Response