2012-04-22 159 views
0

這是我迄今爲止,我有一個滾動和兩個按鈕,我想在滾動,但我不能得到第二個按鈕,因爲它不會滾動到它。如果有人能看到我的代碼中的錯誤,我將不勝感激。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); 

回答

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

大聲笑...我對這點有點生氣。哈哈哈哈,謝謝一個男人。 =) – nfoggia 2012-04-22 02:35:09

+1

沒問題。我仍然在笑的方法名稱... – CodaFi 2012-04-22 02:35:45

+1

哈哈哈我不認爲他們會接受我的應用程序大聲笑 – nfoggia 2012-04-22 03:29:28