0

これは私がこれまでに持っていたものです。スクローラーとスクローラーに配置したい2つのボタンがありますが、スクロールしないため、2番目のボタンに到達できません。誰かが私のコードでエラーを見ることができれば幸いです。

    UIScrollView *mainScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 65, 320, 4000)];
mainScroll.contentSize = CGSizeMake(320, 4000);
mainScroll.showsHorizontalScrollIndicator = YES;
[self.view addSubview:mainScroll];
[mainScroll setScrollEnabled:YES];


UIButton *mainCreateGame = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[mainCreateGame addTarget:self
                   action:@selector(goToCreateGameViewController)
         forControlEvents:UIControlEventTouchUpInside];
[mainScroll addSubview:mainCreateGame];
mainCreateGame.frame = CGRectMake(75, 10, 170, 60);



UIButton *anotherButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[anotherButton addTarget:self
                  action:@selector(goFuckOffApple)
        forControlEvents:UIControlEventTouchUpInside];
[mainScroll addSubview: anotherButton];
anotherButton.frame = CGRectMake(75, 3000, 170, 60);
4

1 に答える 1

1

さて、陽気なメソッド名 (goF**kOffApple、LOL) に加えて、スクロール ビューのフレームをコンテンツと同じサイズに設定しています。フレームとコンテンツのサイズは別の動物です。これを試して:

 UIScrollView *mainScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 65, 320, 395)];
mainScroll.contentSize = CGSizeMake(320, 4000);
mainScroll.showsVerticalScrollIndicator = YES;
[self.view addSubview:mainScroll];
[mainScroll setScrollEnabled:YES];


UIButton *mainCreateGame = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[mainCreateGame addTarget:self
                   action:@selector(goToCreateGameViewController)
         forControlEvents:UIControlEventTouchUpInside];
[mainScroll addSubview:mainCreateGame];
mainCreateGame.frame = CGRectMake(75, 10, 170, 60);



UIButton *anotherButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[anotherButton addTarget:self
                  action:@selector(goFuckOffApple)
        forControlEvents:UIControlEventTouchUpInside];
[mainScroll addSubview: anotherButton];
anotherButton.frame = CGRectMake(75, 3000, 170, 60);
于 2012-04-22T02:20:49.130 に答える