2012-04-22 5 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

lol ... Я был безумно злым в яблоке от этого момента. hahahaha благодарит тонну человека. =) – nfoggia

+1

Нет проблем. Я все еще смеюсь над именем метода ... – CodaFi

+1

hahaha Я не думаю, что они согласятся с моим приложением lol – nfoggia