0

右にスクロールしないスクロール ビューがあります。以下のコードを簡略化しました。ビューと、実際のコードに追加するいくつかの水平ボタンを描画します。ボタン間の空白をドラッグすると、ビューがスクロールします。ボタンに指を置いても、スクロールしません。関連する提案の後、delaysContentTouches = YES 行を追加しようとしましたが、違いはないようです。 UIButtonsを使用したUIScrollview - スプリングボードを再作成する方法は?

私は何を間違っていますか?ティア、ロブ

コードを更新しました

- (void)viewDidLoad {
    l = [self landscapeView];
    [self.view addSubview:l];
    [l release];    
}

- (UIScrollView *) landscapeView {
    // LANDSCAPE VIEW
    UIScrollView *landscapeView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 325)];
    landscapeView.backgroundColor = [UIColor whiteColor];
    landscapeView.delaysContentTouches = YES;
    NSInteger iMargin, runningY, n;
    iMargin = 3;
    runningY = iMargin;

    for (n = 1; n <= 38; n++) {
        //add day labels
        UIButton *templabel = [[UIButton alloc] initWithFrame:CGRectMake(iMargin,runningY,320 - ( 2 * iMargin),20)];
        templabel.backgroundColor = [UIColor grayColor];
        [landscapeView addSubview:templabel];
        [templabel release];
        runningY = runningY + 30;
    }
    landscapeView.contentSize = CGSizeMake( 320, runningY);

    return landscapeView; 
}
4

2 に答える 2

0

起こっていることの 1 つは、landScapeView のゲッターが複雑なコンストラクターであるように見えます...そのため、[self landscapeView] または self.landscapeView を実行するたびに、まったく新しい UIScrollView を作成して操作しています。

.h ファイルで次のようなことを試してみます。

@interface MyClass: MyParent {
  UIScrollView *landscapeView;
}

@property (retain) UIScrollView *landscapeView;

...そしてこれを .m ファイルに:

@implementation MyClass

@synthesize landscapeView;

(void)viewDidLoad 
{ l = [[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 325)] autorelease];
  [self.view addSubview:self.landscapeView]; [l release]; 
  landscapeView.backgroundColor = [UIColor whiteColor];
  landscapeView.delaysContentTouches = YES;
   NSInteger iMargin, runningY, n;
  iMargin = 3;
  runningY = iMargin;
  for (n = 1; n <= 38; n++) { //add day labels 
       UIButton *templabel = [[UIButton alloc] initWithFrame:CGRectMake(iMargin,runningY,320 - ( 2 * iMargin),20)];
       templabel.backgroundColor = [UIColor grayColor]; 
       [landscapeView addSubview:templabel]; 
       [templabel release]; runningY = runningY + 30; 
  } 
  landscapeView.contentSize = CGSizeMake( 320, runningY);

}

于 2009-11-20T20:23:25.197 に答える
0

あなたの結果を複製することはできません。scrollView を作成してボタンを追加すると、ボタンをタッチダウンしてもスクロールがアクティブになります。簡素化されたコードに表示されない他の UIScrollView プロパティを設定したり、メソッドをサブクラス化したりしていますか?

于 2009-11-10T20:27:25.423 に答える