UIScrollView没有正确滚动
问题描述:
这是我迄今为止,我有一个滚动和两个按钮,我想在滚动,但我不能得到第二个按钮,因为它不会滚动到它。如果有人能看到我的代码中的错误,我将不胜感激。UIScrollView没有正确滚动
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);
大声笑...我对这点有点生气。哈哈哈哈,谢谢一个男人。 =) – nfoggia 2012-04-22 02:35:09
没问题。我仍然在笑的方法名称... – CodaFi 2012-04-22 02:35:45
哈哈哈我不认为他们会接受我的应用程序大声笑 – nfoggia 2012-04-22 03:29:28