Iphone UIScrollView未正确滚动

Iphone UIScrollView未正确滚动,iphone,ios,uiscrollview,Iphone,Ios,Uiscrollview,这就是我到目前为止所拥有的,我有一个滚动条和两个按钮,我想在滚动条上,但我不能到达第二个按钮,因为它不会滚动到它。如果有人能看到我代码中的错误,我将不胜感激 UIScrollView *mainScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 65, 320, 4000)]; mainScroll.contentSize = CGSizeMake(320, 4000); mainScroll.showsHorizontal

这就是我到目前为止所拥有的,我有一个滚动条和两个按钮,我想在滚动条上,但我不能到达第二个按钮,因为它不会滚动到它。如果有人能看到我代码中的错误,我将不胜感激

    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);

好吧,除了搞笑的方法名称(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);

英雄联盟那时我有点生苹果的气。哈哈哈,谢谢你,伙计