2010-08-04 80 views
9

我不能讓我的滾動視圖實際滾動。一切顯示正常,除了它只是不會滾動.....下面是我的代碼:iPhone SDK:的UIScrollView不滾動

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 600)]; 
    scrollView.contentSize = CGSizeMake(320, 600); 
    scrollView.scrollEnabled = YES; 
    scrollView.clipsToBounds = YES; 
    [self.view addSubview:scrollView]; 

    planView = [[WorkoutPlanView alloc] initWithImage:[UIImage imageNamed:@"WorkoutTable.png"]]; 
    planView2 = [[WorkoutPlanView alloc] initWithImage:[UIImage imageNamed:@"WorkoutTable.png"]]; 
    planView2.frame = CGRectMake(0, 164, 320, 165); 
    planView3 = [[WorkoutPlanView alloc] initWithImage:[UIImage imageNamed:@"WorkoutTable.png"]]; 
    planView3.frame = CGRectMake(0, 328, 320, 165); 
    planView4 = [[WorkoutPlanView alloc] initWithImage:[UIImage imageNamed:@"WorkoutTable.png"]]; 
    planView4.frame = CGRectMake(0, 505, 320, 165); 
    [scrollView addSubview:planView]; 
    [scrollView addSubview:planView2]; 
    [scrollView addSubview:planView3]; 
    [scrollView addSubview:planView4]; 
} 

我該如何解決這個問題?

回答

21

contentSize必須大於滾動視圖的框架才能滾動任何內容。 :)

在這種情況下,他們都(320, 600)因此改變你的滾動視圖的init到

UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; 
+0

趕上pop850。加一! – ouflak 2015-09-28 12:47:08

0

您的滾動視圖幀應該比contentSize小,所以只有你可以使滾動視圖滾動。