2013-02-10 49 views
0

我努力嘗試,但無法在啓用分頁的情況下在另一個水平scrollView內添加垂直scrollView。我試圖尋找解決方案,但沒有任何幫助。請幫忙。 謝謝。 以下是代碼我曾嘗試:無法將UIScrollView添加到另一個UIscrollView

的for(int i = 0;我< kNumImages;我++){

NSString *imageName = [NSString stringWithFormat:@"dots.png"]; 
    UIImage *image = [UIImage imageNamed:imageName]; 

    UIScrollView *insetScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 300)]; 
    insetScrollView.scrollEnabled = NO; 
    UIView *insetView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 320)]; 


    UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(320*i, 300, 300, 21)]; 
    textLabel.backgroundColor = [UIColor clearColor]; 
    textLabel.text = @"MyRandomText"; 
    UIImageView *imageButton = [[UIImageView alloc] initWithImage:image]; 
    imageButton.frame = CGRectMake(320*i, 0, 320, 260); 

    [insetView addSubview:imageButton]; 
    [insetView addSubview:textLabel]; 
    [insetScrollView addSubview:insetView]; 
    [mainScrollView addSubview: insetScrollView]; 
    [mainScrollView setDelegate:self]; 
    [self.view addSubview:mainScrollView]; 
} 

回答

0

爲什麼你所有insetScrollView設置框原點X = 0?

所以試試這個。

UIScrollView *insetScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(320*i, 0, 320, 300)]; 

mainScrollView<-> 
||    |     |    |    |   || 
||    |     |    |    |   || 
||    |     |    |    |   || 
||    |     |    |    |   || 
||    |     |    |    |   || 
||    |     |    |    |   || 
||    |     |    |    |   || 
||    |     |    |    |   || 
||    |     |    |    |   || 
|| inset0  | inset1  | inset2  | inset3  | inset4 || 
||    |     |    |    |   || 
||    |     |    |    |   || 
||    |     |    |    |   || 
||    |     |    |    |   || 
||    |     |    |    |   || 
||    |     |    |    |   || 
||    |     |    |    |   || 
||    |     |    |    |   || 
||    |     |    |    |   || 
||    |     |    |    |   || 
||    |     |    |    |   || 
||    |     |    |    |   || 
||    |     |    |    |   || 
||    |     |    |    |   || 
+1

謝謝,我得到了我的錯誤。非常感謝。它的工作現在。 – ScarletWitch 2013-02-10 10:06:08