0

通常、チュートリアルでUIScrollViewは、画面のサイズで複数のページについて話します。

画面の最初のページから始めて、2番目のページが少し右側に表示されます。
Ex01

また、スクロールすると、2ページ目でも同じことが起こります。1ページ目と3ページ目が左側/右側に表示されます。
Ex02

このscrollViewは「実装可能」ですか?ページを使用する方法はありますが、画面全体の幅ではありませんか?

4

3 に答える 3

0

スクロール ビューのコンテンツ サイズを設定してみてください

scrollView.contentSize = CGSizeMake(W, 1);

水平方向にスクロールするには、「W」がスクロール ビューの幅よりも大きい数値でなければならないことに注意してください。1 は、コンテンツ サイズの高さを設定する場所です。垂直方向にスクロールする場合は、「1」をスクロールビューの高さよりも大きくします。

于 2012-10-09T04:37:01.430 に答える
0

はい、できます。スクロール ビューのサイズを目的のサイズに変更するだけです。スクロール ビューの (numberOfPages * width) としてのコンテンツ サイズ

scrollView.pagingEnabled = YES;
scrollView.contentSize = CGSizeMake(numberOfPages * scrollView.frame.size.width, 1);

詳細については、このサンプル プロジェクトを参照してください。xib でスクロールビューのサイズを変更するだけです :) お役に立てば幸いです :)

于 2012-10-09T04:39:26.840 に答える
0

-hitTest:withEvent:メソッドを処理するには、スクロール ビュー コンテナー (ScrollViewContainer など) を実装する必要があります。

ScrollViewContainer.h:

@interface BookAlbumScrollViewContainer : UIView {
  UIScrollView * theScrollView_;
}

@property (nonatomic, retain) UIScrollView * theScrollView;

@end

ScrollViewContainer.m:

@implementation BookAlbumScrollViewContainer

@synthesize theScrollView = theScrollView_;

//...

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
  UIView * child = [super hitTest:point withEvent:event];
  if (child == self)
    return self.theScrollView;
  return child;
}

@end

HERE-hitTest:withEvent:は、メソッドに関する関連する QA

スクロール ビューを設定するときは、次のように設定します。

CGFloat yourScrollViewPageWidth = 280.f;
CGRect yourScrollViewFrame = CGRectMake((320.f - yourScrollViewPageWidth) / 2.f, 0.f, yourScrollViewPageWidth, 200.f);
CGRect theScrollViewContainerFrame = CGRectMake(0.f, 0.f, 320.f, 200.f);

// Your scroll view
yourScrollView_ = [[UIScrollView alloc] initWithFrame:yourScrollViewFrame];
//...
[self.view addSubview:bookScrollView_];

// Your scroll view container to handle touches, it should be over |yourScrollView_|
theScrollViewContainer_ = [ScrollViewContainer alloc];
[theScrollViewContainer_ initWithFrame:theScrollViewContainerFrame];
[theScrollViewContainer_ setBookAlbumScrollView:yourScrollView_];
[self.view theScrollViewContainer_];
于 2012-10-09T05:03:42.683 に答える